first import
This commit is contained in:
339
sites/all/modules/fontyourface/LICENSE.txt
Normal file
339
sites/all/modules/fontyourface/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
33
sites/all/modules/fontyourface/README.txt
Normal file
33
sites/all/modules/fontyourface/README.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
1. Installing @font-your-face:
|
||||
==============================
|
||||
|
||||
- Place the extracted module in sites/all/modules/fontyourface
|
||||
- Go to Administration » Modules and enable @font-your-face and one or more of the submodules.
|
||||
- Go to Administration » Configuration » User interface » @font-your-face settings and import the fonts.
|
||||
|
||||
2a. Use @font-your-face via the interface:
|
||||
==========================================
|
||||
- Go to Administration » Appearance » @font-your-face (admin/appearance/fontyourface/browse)
|
||||
to enable some fonts.
|
||||
- Click the 'enable font' for each fonr you want to use.
|
||||
- You can add CSS selectors for each enabled font.
|
||||
|
||||
2b. Using @font-your-face via your theme .info file:
|
||||
====================================================
|
||||
- Open the .info file of your theme (eg bartik.info if your theme is Bartik)
|
||||
- Add fonts like this:
|
||||
|
||||
fonts[google_fonts_api][] = "Contrail One&subset=latin#regular"
|
||||
fonts[fontdeck][] = "Tanger+Serif+Medium+Ultra+Light"
|
||||
|
||||
- The use your stylesheet to enable fonts. Example:
|
||||
h1#site-title { font-family: "1942 Report", serif; }
|
||||
|
||||
Known issues:
|
||||
=============
|
||||
- Note that Internet Explorer has a limit of 32 CSS files, so using @font-your-face on CSS-heavy sites may require
|
||||
turning on CSS aggregation under Administer » Configuration » Development » Performance (admin/config/development/performance).
|
||||
- KERNEST servers are sometimes unreliable, so you may want to download KERNEST fonts and use the Local Fonts module to
|
||||
load them from your server instead. KERNEST provides paid fonts that are not available for use in the API, so those can
|
||||
only be used with the Local Fonts module.
|
||||
- See http://drupal.org/project/fontyourface#support for support options on any issues not mentioned here.
|
137
sites/all/modules/fontyourface/drush/fontyourface.drush.inc
Normal file
137
sites/all/modules/fontyourface/drush/fontyourface.drush.inc
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Drush integration for @font-your-face.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_drush_help().
|
||||
*/
|
||||
function fontyourface_drush_help($section) {
|
||||
switch ($section) {
|
||||
case 'drush:fyf-status':
|
||||
$help = dt('Displays @font-your-face status');
|
||||
return $help;
|
||||
case 'drush:fyf-import':
|
||||
$help = dt('Imports @font-your-face fonts');
|
||||
return $help;
|
||||
case 'meta:fontyourface:title':
|
||||
$help = dt('@font-your-face commands');
|
||||
return $help;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function fontyourface_drush_command() {
|
||||
$items = array();
|
||||
$items['fyf-status'] = array(
|
||||
'callback' => 'fontyourface_fyf_status',
|
||||
'drupal dependencies' => array('fontyourface'),
|
||||
'description' => 'Displays general @font-your-face status information',
|
||||
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
|
||||
'aliases' => array('@s', 'fyfs'),
|
||||
);
|
||||
$items['fyf-import'] = array(
|
||||
'callback' => 'fontyourface_fyf_import',
|
||||
'drupal dependencies' => array('fontyourface'),
|
||||
'description' => 'Imports fonts from one or more providers',
|
||||
'arguments' => array(
|
||||
'providers' => '(optional) A space delimited list of providers.',
|
||||
),
|
||||
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
|
||||
'aliases' => array('@i', 'fyfi'),
|
||||
'examples' => array(
|
||||
'drush @i' => 'Import fonts from all enabled providers.',
|
||||
'drush @i google_fonts_api fontdeck' => 'Import fonts from Google Fonts API and Fontdeck.',
|
||||
),
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for Drush command 'fyf-status'.
|
||||
*/
|
||||
function fontyourface_fyf_status() {
|
||||
// Provider info.
|
||||
$modules = module_implements('fontyourface_info', TRUE);
|
||||
if (count($modules) > 0) {
|
||||
drush_print(dt('Providers enabled (@count):', array('@count' => count($modules))));
|
||||
$rows = array();
|
||||
$rows[] = array(
|
||||
dt('Provider'),
|
||||
dt('Total fonts'),
|
||||
dt('Enabled fonts'),
|
||||
);
|
||||
foreach ($modules as $module) {
|
||||
$row = array();
|
||||
$row[] = $module;
|
||||
$row[] = fontyourface_count_fonts($module);
|
||||
$row[] = fontyourface_count_fonts($module, TRUE);
|
||||
$rows[] = $row;
|
||||
}
|
||||
drush_print_table($rows, TRUE);
|
||||
}
|
||||
else {
|
||||
drush_print(dt('No font providers are enabled.'));
|
||||
// If there are no providers, we can call it quits as there will be no
|
||||
// fonts either.
|
||||
return;
|
||||
}
|
||||
// Font info.
|
||||
$fonts = fontyourface_get_fonts('enabled = 1');
|
||||
if (count($fonts) > 0) {
|
||||
drush_print(dt('Fonts enabled (@count):', array('@count' => count($fonts))));
|
||||
$rows = array();
|
||||
$rows[] = array(
|
||||
dt('Font'),
|
||||
dt('Provider'),
|
||||
dt('CSS selector'),
|
||||
);
|
||||
foreach ($fonts as $font) {
|
||||
$row = array();
|
||||
$row[] = $font->name;
|
||||
$row[] = $font->provider;
|
||||
$row[] = $font->css_selector;
|
||||
$rows[] = $row;
|
||||
}
|
||||
drush_print_table($rows, TRUE);
|
||||
}
|
||||
else {
|
||||
drush_print(dt('No fonts are enabled.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for Drush command 'fyf-import'.
|
||||
*/
|
||||
function fontyourface_fyf_import() {
|
||||
$providers = _convert_csv_to_array(func_get_args());
|
||||
if (empty($providers)) {
|
||||
// If no providers were specified, get all existing import functions.
|
||||
$providers = module_implements('fontyourface_import');
|
||||
}
|
||||
foreach ($providers as $provider) {
|
||||
$import_function = $provider . '_fontyourface_import';
|
||||
if ($provider == 'fontsquirrel') {
|
||||
drush_set_error(dt("Font Squirrel import is not supported yet. We're working on that."));
|
||||
}
|
||||
elseif (!function_exists($import_function)) {
|
||||
drush_set_error(dt("Unknown provider '@provider', or there is no import function for it; run 'drush fyf-status' to see enabled providers", array('@provider' => $provider)));
|
||||
}
|
||||
else {
|
||||
$before = fontyourface_count_fonts($provider);
|
||||
if ($import_function()) {
|
||||
$message = dt('Imported fonts from @provider.', array('@provider' => $provider));
|
||||
drush_log($message, 'success');
|
||||
$after = fontyourface_count_fonts($provider);
|
||||
drush_print(dt('@provider now has @fonts fonts (+@diff).', array('@provider' => $provider, '@fonts' => $after, '@diff' => $after - $before)));
|
||||
}
|
||||
else {
|
||||
drush_set_error(dt('Font import from @provider failed.', array('@provider' => $provider)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
132
sites/all/modules/fontyourface/fontyourface.features.inc
Normal file
132
sites/all/modules/fontyourface/fontyourface.features.inc
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Integrates Features for @font-your-face.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_options. [component_hook]
|
||||
*
|
||||
* This hook will alert features of which specific items of this component may
|
||||
* be exported. For instances, in this case, we want to make available all the
|
||||
* existing items. If there are no items to be exported, this component will
|
||||
* not be made available in the features export page.
|
||||
*
|
||||
* @return array
|
||||
* A keyed array of items, suitable for use with a FormAPI select or
|
||||
* checkboxes element.
|
||||
*/
|
||||
function fontyourface_features_export_options() {
|
||||
$fonts = array();
|
||||
|
||||
foreach (fontyourface_get_fonts('enabled = 1') as $font) {
|
||||
$fonts[$font->name] = $font->name;
|
||||
}
|
||||
|
||||
return $fonts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export [component hook]
|
||||
*
|
||||
* This is a component hook, rather then a module hook, therefore this is the
|
||||
* callback from hook_features_api which relates to the specific component we
|
||||
* are looking to export. When a specific instance of the component we are
|
||||
* looking to export is selected, this will include the necessariy item, plus
|
||||
* any dependencies into our export array.
|
||||
*
|
||||
* @param array $data
|
||||
* this is the machine name for the component in question
|
||||
* @param array &$export
|
||||
* array of all components to be exported
|
||||
* @param string $module_name
|
||||
* The name of the feature module to be generated.
|
||||
* @return array
|
||||
* The pipe array of further processors that should be called
|
||||
*/
|
||||
function fontyourface_features_export($data, &$export, $module_name = '') {
|
||||
|
||||
// fontyourface_default_fonts integration is provided by Features.
|
||||
$export['dependencies']['features'] = 'features';
|
||||
$export['dependencies']['fontyourface'] = 'fontyourface';
|
||||
|
||||
// Add dependencies for each font.
|
||||
$fonts = fontyourface_get_fonts('enabled = 1');
|
||||
|
||||
foreach ($fonts as $font) {
|
||||
if (in_array($font->name, $data)) {
|
||||
|
||||
// Make the font provider required
|
||||
$export['dependencies'][$font->provider] = $font->provider;
|
||||
|
||||
$export['features']['fontyourface'][$font->name] = $font->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $export;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_render. [component hook]
|
||||
*
|
||||
* This hook will be invoked in order to export
|
||||
* Component hook. The hook should be implemented using the name ot the
|
||||
* component, not the module, eg. [component]_features_export() rather than
|
||||
* [module]_features_export().
|
||||
*
|
||||
* Render one or more component objects to code.
|
||||
*
|
||||
* @param string $module_name
|
||||
* The name of the feature module to be exported.
|
||||
* @param array $data
|
||||
* An array of machine name identifiers for the objects to be rendered.
|
||||
* @param array $export
|
||||
* The full export array of the current feature being exported. This is only
|
||||
* passed when hook_features_export_render() is invoked for an actual feature
|
||||
* update or recreate, not during state checks or other operations.
|
||||
* @return array
|
||||
* An associative array of rendered PHP code where the key is the name of the
|
||||
* hook that should wrap the PHP code. The hook should not include the name
|
||||
* of the module, e.g. the key for `hook_example` should simply be `example`.
|
||||
*/
|
||||
function fontyourface_features_export_render($module, $data) {
|
||||
$fonts = fontyourface_get_fonts('enabled = 1');
|
||||
$code = array();
|
||||
foreach ($data as $name) {
|
||||
foreach ($fonts as $font) {
|
||||
if ($font->name == $name) {
|
||||
// We don't want to break the entity cache, so we need to clone the
|
||||
// font before unsetting the id.
|
||||
$font = clone $font;
|
||||
unset($font->fid);
|
||||
unset($font->tags);
|
||||
$code[$name] = $font;
|
||||
}
|
||||
}
|
||||
}
|
||||
$code = " return " . features_var_export($code, ' ') . ";";
|
||||
return array('fontyourface_features_default_font' => $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_revert().
|
||||
*/
|
||||
function fontyourface_features_revert($module) {
|
||||
fontyourface_features_rebuild($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_rebuild().
|
||||
*
|
||||
* Rebuilds @font-your-face fonts from code defaults.
|
||||
*/
|
||||
function fontyourface_features_rebuild($module) {
|
||||
$saved_fonts = module_invoke($module, 'fontyourface_features_default_font');
|
||||
|
||||
foreach ($saved_fonts as $key => $font) {
|
||||
$font = (object) $font;
|
||||
$font->tags = array();
|
||||
$saved = fontyourface_save_font($font, TRUE);
|
||||
}
|
||||
}
|
12
sites/all/modules/fontyourface/fontyourface.info
Normal file
12
sites/all/modules/fontyourface/fontyourface.info
Normal file
@@ -0,0 +1,12 @@
|
||||
name = @font-your-face
|
||||
description = Manages web fonts.
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
files[] = fontyourface.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
302
sites/all/modules/fontyourface/fontyourface.install
Normal file
302
sites/all/modules/fontyourface/fontyourface.install
Normal file
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Adds fontyourface tables for tracking fonts.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Re-usable function for the 7.2 schema.
|
||||
*/
|
||||
function fontyourface_7200_schema() {
|
||||
|
||||
$schema = array();
|
||||
|
||||
$schema['fontyourface_font'] = array(
|
||||
'description' => 'Font information.',
|
||||
'fields' => array(
|
||||
'fid' => array(
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'Primary Key: Unique font ID.',
|
||||
),
|
||||
'name' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The font name.',
|
||||
),
|
||||
'enabled' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'size' => 'tiny',
|
||||
'description' => 'Whether or not the font is enabled. (0 = disabled, 1 = enabled)',
|
||||
),
|
||||
'url' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'A URL for the font.',
|
||||
),
|
||||
'provider' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The module providing the font.',
|
||||
),
|
||||
'css_selector' => array(
|
||||
'type' => 'text',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
'description' => 'CSS selector for applying the font.',
|
||||
),
|
||||
'css_family' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'CSS family for the font.',
|
||||
),
|
||||
'css_style' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'CSS style for the font.',
|
||||
),
|
||||
'css_weight' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'CSS weight for the font.',
|
||||
),
|
||||
'css_fallbacks' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'CSS fallbacks for the font.',
|
||||
),
|
||||
'foundry' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'Foundry for the font.',
|
||||
),
|
||||
'foundry_url' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'URL for foundry for the font.',
|
||||
),
|
||||
'license' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'License for the font.',
|
||||
),
|
||||
'license_url' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'URL for license for the font.',
|
||||
),
|
||||
'designer' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'Designer for the font.',
|
||||
),
|
||||
'designer_url' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
'description' => 'URL for designer for the font.',
|
||||
),
|
||||
'metadata' => array(
|
||||
'type' => 'text',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
'description' => 'Additional serialized metadata about the font.',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'enabled' => array('enabled'),
|
||||
),
|
||||
'unique keys' => array(
|
||||
'url' => array('url'),
|
||||
),
|
||||
'primary key' => array('fid'),
|
||||
);
|
||||
|
||||
$schema['fontyourface_tag'] = array(
|
||||
'description' => 'Font tag information.',
|
||||
'fields' => array(
|
||||
'tid' => array(
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'Primary Key: Unique tag ID.',
|
||||
),
|
||||
'name' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The font name.',
|
||||
),
|
||||
'type' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 10,
|
||||
'not null' => TRUE,
|
||||
'default' => 'tag',
|
||||
'description' => 'Indicator that describes the type of tag (term, subset, etc).',
|
||||
),
|
||||
),
|
||||
'primary key' => array('tid'),
|
||||
);
|
||||
|
||||
$schema['fontyourface_tag_font'] = array(
|
||||
'description' => 'Relationship information between fonts and tags.',
|
||||
'fields' => array(
|
||||
'fid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'Foreign Key: the unique ID of the font.',
|
||||
),
|
||||
'tid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'Foreign Key: the unique ID of the tag.',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'fid' => array('fid'),
|
||||
'tid' => array('tid'),
|
||||
),
|
||||
'primary key' => array('fid', 'tid'),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
|
||||
} // fontyourface_7200_schema
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function fontyourface_schema() {
|
||||
|
||||
return fontyourface_7200_schema();
|
||||
|
||||
} // fontyourface_schema
|
||||
|
||||
/**
|
||||
* Moves admin interface to fontyourface_ui module.
|
||||
*/
|
||||
function fontyourface_update_7200() {
|
||||
|
||||
// Move UI over to new fontyourface_ui module.
|
||||
|
||||
module_enable(array('fontyourface_ui'));
|
||||
views_invalidate_cache();
|
||||
|
||||
// Add new fields to schema.
|
||||
|
||||
$schema = fontyourface_7200_schema();
|
||||
db_add_field('fontyourface_font', 'css_fallbacks', $schema['fontyourface_font']['fields']['css_fallbacks']);
|
||||
db_add_field('fontyourface_font', 'designer', $schema['fontyourface_font']['fields']['designer']);
|
||||
db_add_field('fontyourface_font', 'designer_url', $schema['fontyourface_font']['fields']['designer_url']);
|
||||
|
||||
} // fontyourface_update_7200
|
||||
|
||||
/**
|
||||
* Distinct subsets from tags using an extra 'type' column.
|
||||
*/
|
||||
function fontyourface_update_7201() {
|
||||
|
||||
views_invalidate_cache();
|
||||
|
||||
// Add new column to schema.
|
||||
|
||||
$schema = fontyourface_7200_schema();
|
||||
db_add_field('fontyourface_tag', 'type', $schema['fontyourface_tag']['fields']['type']);
|
||||
|
||||
// Convert existing Google Fonts tags to subsets
|
||||
$query = db_select('fontyourface_tag', 't');
|
||||
$query->innerJoin('fontyourface_tag_font', 'tf', 'tf.tid = t.tid');
|
||||
$query->innerJoin('fontyourface_font', 'f', 'f.fid = tf.fid');
|
||||
$query->distinct();
|
||||
$result = $query->fields('t', array('tid'))
|
||||
->condition('f.provider', 'google_fonts_api')
|
||||
->execute();
|
||||
|
||||
foreach ($result as $font) {
|
||||
db_update('fontyourface_tag')
|
||||
->fields(array('type' => 'subset'))
|
||||
->condition('tid', $font->tid)
|
||||
->execute();
|
||||
} // foreach
|
||||
|
||||
} // fontyourface_update_7201
|
||||
|
||||
/**
|
||||
* Make the 'url' column unique to enable exportables
|
||||
*/
|
||||
function fontyourface_update_7202() {
|
||||
|
||||
$schema = fontyourface_7200_schema();
|
||||
try {
|
||||
db_add_unique_key('fontyourface_font', 'url', array('url'));
|
||||
}
|
||||
catch (DatabaseSchemaObjectExistsException $e) {
|
||||
// Fail silently.
|
||||
}
|
||||
|
||||
} // fontyourface_update_7202
|
||||
|
||||
/**
|
||||
* Remove single quotes from CSS selectors
|
||||
*/
|
||||
function fontyourface_update_7203() {
|
||||
|
||||
// Removed - this will not work on SQLite databases.
|
||||
//db_query("UPDATE {fontyourface_font} SET css_family = REPLACE(css_family, '\'', '');");
|
||||
|
||||
} // fontyourface_update_7203
|
||||
|
||||
/**
|
||||
* Remove single quotes from CSS selectors - properly this time.
|
||||
*/
|
||||
function fontyourface_update_7204() {
|
||||
db_update('fontyourface_font')
|
||||
->expression('css_family', "REPLACE(css_family, '''', '')")
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function fontyourface_uninstall() {
|
||||
|
||||
variable_del('fontyourface_short_preview_text');
|
||||
variable_del('fontyourface_detailed_logging');
|
||||
variable_del('fontyourface_css_md5');
|
||||
|
||||
} // fontyourface_uninstall
|
743
sites/all/modules/fontyourface/fontyourface.module
Normal file
743
sites/all/modules/fontyourface/fontyourface.module
Normal file
@@ -0,0 +1,743 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function fontyourface_permission() {
|
||||
|
||||
return array(
|
||||
'administer @font-your-face' => array(
|
||||
'title' => t('administer @font-your-face'),
|
||||
'description' => t('Change which fonts are enabled using the admin interface.'),
|
||||
),
|
||||
);
|
||||
|
||||
} // fontyourface_perm
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function fontyourface_init() {
|
||||
|
||||
fontyourface_add_theme_info_fonts();
|
||||
|
||||
} // fontyourface_init
|
||||
|
||||
/**
|
||||
* Load a font from the database using its URL
|
||||
*/
|
||||
function fontyourface_load_font_by_url($url) {
|
||||
|
||||
if ($font = db_query('SELECT * FROM {fontyourface_font} WHERE url LIKE :url', array(':url' => $url))->fetchObject()) {
|
||||
return $font;
|
||||
} // if
|
||||
|
||||
return array();
|
||||
|
||||
} // fontyourface_load_font_by_url
|
||||
|
||||
/**
|
||||
* Load and display fonts that have been added through THEMENAME.info.
|
||||
*/
|
||||
function fontyourface_add_theme_info_fonts() {
|
||||
|
||||
$theme_declarations = fontyourface_parse_theme_info_file();
|
||||
|
||||
if (isset($theme_declarations)) {
|
||||
|
||||
foreach ($theme_declarations as $font_provider => $fonts) {
|
||||
|
||||
if (module_exists($font_provider)) {
|
||||
|
||||
foreach ($fonts as $declaration) {
|
||||
|
||||
$info_function = $font_provider . '_fontyourface_info';
|
||||
|
||||
if (function_exists($info_function)) {
|
||||
|
||||
$provider_info = $info_function();
|
||||
$font_url = $provider_info['base_path'] . trim($declaration);
|
||||
$font = fontyourface_load_font_by_url($font_url);
|
||||
|
||||
if (!empty($font)) {
|
||||
|
||||
$font->css_selector = '<none>';
|
||||
fontyourface_font_registry($font);
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
if (fontyourface_count_fonts($font_provider) > 0) {
|
||||
|
||||
drupal_set_message(t('The font declaration %declaration that is added to the theme .info file cannot be loaded. Make sure the font exists in the %provider font list.', array('%declaration' => $declaration, '%provider' => $font_provider)), 'error');
|
||||
|
||||
} //if
|
||||
elseif (module_exists('fontyourface_ui')) {
|
||||
|
||||
drupal_set_message(t('The %provider font that is added to the theme .info file cannot be loaded. This is probably because the import has not been run yet. !import to add fonts.', array('%provider' => check_plain($font_provider), '!import' => l(t('Run import'), 'admin/config/user-interface/fontyourface'))), 'error');
|
||||
|
||||
} // elseif
|
||||
else {
|
||||
|
||||
drupal_set_message(t('The %provider font that is added to the theme .info file cannot be loaded. This is probably because the import has not been run yet. Enable !module module and run import to add fonts.', array('%provider' => check_plain($font_provider), '!module' => l('@font-your-face UI', 'admin/modules', array('fragment' => 'edit-modules-font-your-face')))), 'error');
|
||||
|
||||
} // else
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
else {
|
||||
drupal_set_message(t('The font provider @provider is not enabled yet. Please <a href="!module_path">enable</a> it first.', array('@provider' => $font_provider, '!module_path' => url('admin/modules', array('fragment' => 'edit-modules-font-your-face')))), 'error');
|
||||
} // else
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
|
||||
} // fontyourface_add_theme_info_fonts
|
||||
|
||||
/**
|
||||
* Returns info about the font provider for a given font.
|
||||
*
|
||||
* $font = Object: the full $font object.
|
||||
* $info_part = String: if this is given, we only return a string instead of an array.
|
||||
*/
|
||||
function fontyourface_provider_info($font, $info_part = NULL) {
|
||||
|
||||
$provider_info = array();
|
||||
|
||||
if (!empty($font->provider)) {
|
||||
|
||||
$font_provider = $font->provider;
|
||||
$info_function = $font_provider . '_fontyourface_info';
|
||||
|
||||
if (function_exists($info_function)) {
|
||||
$provider_info = $info_function();
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
return empty($info_part) ? $provider_info : $provider_info[$info_part];
|
||||
|
||||
} // fontyourface_provider_info
|
||||
|
||||
/**
|
||||
* Returns the number of fonts that exist in the database.
|
||||
*
|
||||
* @param string $provider
|
||||
* (optional) Filter by provider (e.g. 'google_fonts_api').
|
||||
* @param bool $status
|
||||
* (optional) Filter by status of the font (NULL = all, TRUE = enabled,
|
||||
* FALSE = disabled).
|
||||
*/
|
||||
function fontyourface_count_fonts($provider = NULL, $status = NULL) {
|
||||
|
||||
$query = db_select('fontyourface_font', 'fonts');
|
||||
$query->fields('fonts');
|
||||
|
||||
if (!empty($provider)) {
|
||||
$query->condition('provider', $provider);
|
||||
} // if
|
||||
if (!empty($status)) {
|
||||
$query->condition('enabled', (int) $status);
|
||||
} // if
|
||||
|
||||
$count = $query->execute()->rowCount();
|
||||
|
||||
return $count;
|
||||
|
||||
} //fontyourface_count_fonts
|
||||
|
||||
/**
|
||||
* Implements template_preprocess_html().
|
||||
*/
|
||||
function fontyourface_preprocess_html(&$vars) {
|
||||
|
||||
$fonts = fontyourface_font_registry() + fontyourface_get_fonts();
|
||||
|
||||
$css = fontyourface_generate_css($fonts);
|
||||
$css_md5 = md5($css);
|
||||
|
||||
if ($css_md5 != variable_get('fontyourface_css_md5', '')) {
|
||||
|
||||
fontyourface_rewrite_css($css);
|
||||
variable_set('fontyourface_css_md5', $css_md5);
|
||||
|
||||
} // if
|
||||
|
||||
if ($css != '') {
|
||||
fontyourface_add_css_in_preprocess($vars, 'fontyourface/font.css');
|
||||
} // if
|
||||
|
||||
$vars['fontyourface'] = $fonts;
|
||||
|
||||
} // fontyourface_preprocess_html
|
||||
|
||||
/**
|
||||
* Generates CSS.
|
||||
*/
|
||||
function fontyourface_generate_css($fonts = FALSE) {
|
||||
|
||||
// Get font list.
|
||||
|
||||
if (!$fonts) {
|
||||
$fonts = fontyourface_font_registry() + fontyourface_get_fonts();
|
||||
} // if
|
||||
|
||||
// Generate CSS.
|
||||
|
||||
$css = '';
|
||||
|
||||
foreach ($fonts as $font) {
|
||||
|
||||
$font_css = fontyourface_font_css($font);
|
||||
|
||||
if ($font_css != '' && $font->css_selector != '' && $font->css_selector != '<none>') {
|
||||
$css .= $font->css_selector . ' { ' . $font_css . ' }' . "\n";
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
return $css;
|
||||
|
||||
} // fontyourface_generate_css
|
||||
|
||||
/**
|
||||
* Re-writes fonts.css file.
|
||||
*/
|
||||
function fontyourface_rewrite_css($css) {
|
||||
|
||||
// Write CSS.
|
||||
|
||||
$destination = file_stream_wrapper_uri_normalize('public://fontyourface/font.css');
|
||||
$destination_directory = dirname($destination);
|
||||
|
||||
if (file_prepare_directory($destination_directory, FILE_CREATE_DIRECTORY)) {
|
||||
file_unmanaged_save_data($css, $destination, FILE_EXISTS_REPLACE);
|
||||
} // if
|
||||
|
||||
} // fontyourface_rewrite_css
|
||||
|
||||
/**
|
||||
* Adds a stylesheet in preprocess
|
||||
*/
|
||||
function fontyourface_add_css_in_preprocess(&$vars, $css_path, $type = 'public') {
|
||||
|
||||
if ($type == 'remote') {
|
||||
|
||||
drupal_add_css($css_path, array('type' => 'external', 'group' => CSS_THEME));
|
||||
$vars['styles'] = drupal_get_css();
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
if ($type == 'public') {
|
||||
|
||||
$css_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . $css_path;
|
||||
|
||||
} // if
|
||||
|
||||
drupal_add_css($css_path, array('group' => CSS_THEME, 'basename' => 'fontyourface-' . md5($css_path)));
|
||||
$vars['styles'] = drupal_get_css();
|
||||
|
||||
} // else
|
||||
|
||||
} // fontyourface_add_css_in_preproce
|
||||
|
||||
/**
|
||||
* Gets fonts, defaults to all enabled.
|
||||
*/
|
||||
function fontyourface_get_fonts($where = "enabled = 1 AND css_selector != ''", $order_by = 'name ASC') {
|
||||
|
||||
$fonts = array();
|
||||
|
||||
$results = db_query('SELECT * FROM {fontyourface_font} WHERE ' . $where . ' ORDER BY ' . $order_by);
|
||||
|
||||
while ($result = $results->fetchObject()) {
|
||||
fontyourface_add_font_tags($result);
|
||||
$fonts[] = $result;
|
||||
} // while
|
||||
|
||||
return $fonts;
|
||||
|
||||
} // fontyourface_get_fonts
|
||||
|
||||
/**
|
||||
* Gets a single font.
|
||||
*/
|
||||
function fontyourface_get_font($fid, $clear = FALSE) {
|
||||
|
||||
static $fonts = array();
|
||||
|
||||
if ($clear) {
|
||||
$fonts = array();
|
||||
} // if
|
||||
|
||||
if (!isset($fonts[$fid])) {
|
||||
|
||||
$fonts[$fid] = db_query('SELECT * FROM {fontyourface_font} WHERE fid = :fid', array(':fid' => $fid))->fetchObject();
|
||||
fontyourface_add_font_tags($fonts[$fid]);
|
||||
|
||||
} // if
|
||||
|
||||
return $fonts[$fid];
|
||||
|
||||
} // fontyourface_get_font
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_features_api().
|
||||
*/
|
||||
function fontyourface_features_api() {
|
||||
return array(
|
||||
'fontyourface' => array(
|
||||
'name' => '@font-your-face',
|
||||
'file' => drupal_get_path('module', 'fontyourface') . '/fontyourface.features.inc',
|
||||
'default_hook' => 'fontyourface_features_default_font',
|
||||
'feature_source' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds tags to a font object.
|
||||
*/
|
||||
function fontyourface_add_font_tags(&$font) {
|
||||
|
||||
$font->tags = array();
|
||||
|
||||
$query = db_select('fontyourface_tag', 't');
|
||||
$tag_font_alias = $query->join('fontyourface_tag_font', 'tf', 'tf.tid = t.tid');
|
||||
$query->condition($tag_font_alias . '.fid', $font->fid);
|
||||
$query->fields('t');
|
||||
$result = $query->execute();
|
||||
|
||||
foreach ($result as $tag) {
|
||||
$font->tags[$tag->tid] = $tag->name;
|
||||
} // while
|
||||
|
||||
} // fontyourface_add_tags_to_font
|
||||
|
||||
/**
|
||||
* Runs the font import of the given provider. Triggered
|
||||
* from the UI interface and when a provider is enabled.
|
||||
*/
|
||||
function fontyourface_import_fonts($provider) {
|
||||
|
||||
if (module_exists($provider)) {
|
||||
|
||||
$info_function = $provider . '_fontyourface_info';
|
||||
$provider_info = $info_function();
|
||||
|
||||
$import_function = $provider . '_fontyourface_import';
|
||||
if ($import_function()) {
|
||||
drupal_set_message(t('@provider import complete.', array('@provider' => $provider_info['name'])));
|
||||
}
|
||||
|
||||
} // if
|
||||
|
||||
} // fontyourface_import_fonts
|
||||
|
||||
/**
|
||||
* Enables a single font.
|
||||
*/
|
||||
function fontyourface_enable_font(&$font) {
|
||||
|
||||
db_update('fontyourface_font')
|
||||
->fields(array('enabled' => 1))
|
||||
->condition('fid', $font->fid)
|
||||
->execute();
|
||||
$font->enabled = 1;
|
||||
|
||||
$enable_function = $font->provider . '_fontyourface_enable';
|
||||
|
||||
if (function_exists($enable_function)) {
|
||||
return $enable_function($font);
|
||||
} // if
|
||||
|
||||
return TRUE;
|
||||
|
||||
} // fontyourface_enable_font
|
||||
|
||||
/**
|
||||
* Disables a single font.
|
||||
*/
|
||||
function fontyourface_disable_font(&$font) {
|
||||
|
||||
db_update('fontyourface_font')
|
||||
->fields(array('enabled' => 0))
|
||||
->condition('fid', $font->fid)
|
||||
->execute();
|
||||
$font->enabled = 0;
|
||||
|
||||
$disable_function = $font->provider . '_fontyourface_disable';
|
||||
|
||||
if (function_exists($disable_function)) {
|
||||
return $disable_function($font);
|
||||
} // if
|
||||
|
||||
return TRUE;
|
||||
|
||||
} // fontyourface_disable_font
|
||||
|
||||
/**
|
||||
* Sets a font's CSS selector.
|
||||
*/
|
||||
function fontyourface_set_css_selector(&$font, $css_selector) {
|
||||
|
||||
db_update('fontyourface_font')
|
||||
->fields(array('css_selector' => $css_selector))
|
||||
->condition('fid', $font->fid)
|
||||
->execute();
|
||||
$font->css_selector = $css_selector;
|
||||
|
||||
$selector_function = $font->provider . '_fontyourface_selector_update';
|
||||
|
||||
if (function_exists($selector_function)) {
|
||||
return $selector_function($font);
|
||||
} // if
|
||||
|
||||
} // fontyourface_set_css_selector
|
||||
|
||||
/**
|
||||
* Sets a font's CSS fallbacks.
|
||||
*/
|
||||
function fontyourface_set_css_fallbacks(&$font, $css_fallbacks) {
|
||||
|
||||
db_update('fontyourface_font')
|
||||
->fields(array('css_fallbacks' => $css_fallbacks))
|
||||
->condition('fid', $font->fid)
|
||||
->execute();
|
||||
$font->css_fallbacks = $css_fallbacks;
|
||||
|
||||
} // fontyourface_set_css_fallbacks
|
||||
|
||||
/**
|
||||
* Adds or updates font, depending on whether it already exists.
|
||||
*/
|
||||
function fontyourface_save_font(&$font, $revert = FALSE) {
|
||||
|
||||
$tags = array();
|
||||
if (!empty($font->tags)) {
|
||||
$tags = $font->tags;
|
||||
unset($font->tags);
|
||||
}
|
||||
|
||||
$exists = db_query("SELECT fid FROM {fontyourface_font} WHERE url = :url", array(':url' => $font->url))->fetchObject();
|
||||
|
||||
if ($exists) {
|
||||
|
||||
$existing_font = fontyourface_get_font($exists->fid);
|
||||
|
||||
$font->fid = $existing_font->fid;
|
||||
|
||||
if (!$revert) {
|
||||
// Keep status, selector, and tags the same.
|
||||
$font->enabled = $existing_font->enabled;
|
||||
$font->css_selector = $existing_font->css_selector;
|
||||
}
|
||||
|
||||
fontyourface_add_font_tags($font);
|
||||
drupal_write_record('fontyourface_font', $font, 'fid');
|
||||
$tags = $font->tags;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_write_record('fontyourface_font', $font);
|
||||
|
||||
} // else
|
||||
|
||||
db_delete('fontyourface_tag_font')
|
||||
->condition('fid', $font->fid)
|
||||
->execute();
|
||||
|
||||
if (!is_array($tags)) {
|
||||
$tags = array();
|
||||
} // if
|
||||
|
||||
fontyourface_add_tags_to_font($tags, $font->fid);
|
||||
|
||||
$font->tags = $tags;
|
||||
|
||||
} // fontyourface_save_font
|
||||
|
||||
/**
|
||||
* Adds tags to font.
|
||||
*/
|
||||
function fontyourface_add_tags_to_font($tags, $fid) {
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
|
||||
if (is_object($tag)) {
|
||||
$tag_object = $tag;
|
||||
}
|
||||
else{
|
||||
$tag_object = new StdClass;
|
||||
$tag_object->name = $tag;
|
||||
$tag_object->type = 'tag';
|
||||
}
|
||||
|
||||
fontyourface_save_tag($tag_object);
|
||||
|
||||
$tag_font = new StdClass;
|
||||
$tag_font->tid = $tag_object->tid;
|
||||
$tag_font->fid = $fid;
|
||||
|
||||
drupal_write_record('fontyourface_tag_font', $tag_font);
|
||||
|
||||
} // forach
|
||||
|
||||
} // fontyourface_add_tags_to_font
|
||||
|
||||
/**
|
||||
* Adds tag if it doesn't already exist.
|
||||
*/
|
||||
function fontyourface_save_tag(&$tag) {
|
||||
|
||||
$exists = db_query("SELECT tid FROM {fontyourface_tag} WHERE name = :name", array(':name' => $tag->name))->fetchObject();
|
||||
|
||||
if ($exists) {
|
||||
// Check that existing tag is lowercase
|
||||
if (!ctype_lower($tag->name)) {
|
||||
$tag->name = drupal_strtolower($tag->name);
|
||||
}
|
||||
$tag->tid = $exists->tid;
|
||||
} // if
|
||||
else {
|
||||
$tag->name = drupal_strtolower($tag->name);
|
||||
drupal_write_record('fontyourface_tag', $tag);
|
||||
} // else
|
||||
|
||||
} // fontyourface_save_tag
|
||||
|
||||
/**
|
||||
* Gets preview from provider, if available.
|
||||
*/
|
||||
function fontyourface_preview($font, $text, $size) {
|
||||
|
||||
fontyourface_font_registry($font);
|
||||
|
||||
$function = $font->provider . '_fontyourface_preview';
|
||||
|
||||
if (function_exists($function)) {
|
||||
return $function($font, $text, $size);
|
||||
} // if
|
||||
|
||||
return $text;
|
||||
|
||||
} // fontyourface_preview
|
||||
|
||||
/**
|
||||
* Gets preview text from provider, if available.
|
||||
*/
|
||||
function fontyourface_short_preview_text($font) {
|
||||
|
||||
$function = $font->provider . '_fontyourface_short_preview_text';
|
||||
|
||||
if (function_exists($function)) {
|
||||
return $function($font);
|
||||
} // if
|
||||
|
||||
return variable_get('fontyourface_short_preview_text', 'AaGg');
|
||||
|
||||
} // fontyourface_short_preview_text
|
||||
|
||||
/**
|
||||
* Manages registry of fonts used on current page, to provide
|
||||
* list to fontyourface_preprocess_html().
|
||||
*/
|
||||
function fontyourface_font_registry($font = FALSE, $clear = FALSE) {
|
||||
|
||||
static $fonts = array();
|
||||
|
||||
if ($clear) {
|
||||
$fonts = array();
|
||||
} // if
|
||||
|
||||
if ($font) {
|
||||
$fonts[$font->fid] = $font;
|
||||
} // if
|
||||
|
||||
return $fonts;
|
||||
|
||||
} // fontyourface_font_registry
|
||||
|
||||
/**
|
||||
* Creates CSS with any properties set on font.
|
||||
*/
|
||||
function fontyourface_font_css($font) {
|
||||
|
||||
$css = array();
|
||||
|
||||
if ($font->css_family) {
|
||||
|
||||
// Enclose font family definition in single quotes if not already enclosed.
|
||||
if ($font->css_family[0] === "'") {
|
||||
$family_list = $font->css_family;
|
||||
} // if
|
||||
else {
|
||||
$family_list = "'" . $font->css_family . "'";
|
||||
} // else
|
||||
|
||||
if ($font->css_fallbacks) {
|
||||
$family_list .= ', ' . $font->css_fallbacks;
|
||||
} // if
|
||||
|
||||
$css[] = 'font-family: ' . $family_list . ';';
|
||||
|
||||
} // if
|
||||
|
||||
if ($font->css_style) {
|
||||
$css[] = 'font-style: ' . $font->css_style . ';';
|
||||
} // if
|
||||
|
||||
if ($font->css_weight) {
|
||||
$css[] = 'font-weight: ' . $font->css_weight . ';';
|
||||
} // if
|
||||
|
||||
return implode(' ', $css);
|
||||
|
||||
} // fontyourface_font_c
|
||||
|
||||
/**
|
||||
* Removes all fonts and related tags from given provider.
|
||||
*/
|
||||
function fontyourface_provider_disable($provider) {
|
||||
|
||||
// Delete all fonts.
|
||||
|
||||
db_delete('fontyourface_font')
|
||||
->condition('provider', $provider)
|
||||
->execute();
|
||||
|
||||
fontyourface_delete_unused_tags();
|
||||
|
||||
} // fontyourface_provider_disable
|
||||
|
||||
/**
|
||||
* Deletes all unused tags.
|
||||
*/
|
||||
function fontyourface_delete_unused_tags() {
|
||||
|
||||
// Delete all unused font-tag relationships.
|
||||
|
||||
$missing_font_query = db_select('fontyourface_tag_font', 'tf');
|
||||
$font_alias = $missing_font_query->leftJoin('fontyourface_font', 'f', 'tf.fid = f.fid');
|
||||
$missing_fonts = $missing_font_query
|
||||
->isNull($font_alias . '.fid')
|
||||
->fields('tf', array('fid'))
|
||||
->execute();
|
||||
|
||||
$missing_fids = array();
|
||||
|
||||
foreach ($missing_fonts as $missing_font) {
|
||||
$missing_fids[] = $missing_font->fid;
|
||||
} // foreach
|
||||
|
||||
if (count($missing_fids) > 0) {
|
||||
|
||||
db_delete('fontyourface_tag_font')
|
||||
->condition('fid', $missing_fids, 'IN')
|
||||
->execute();
|
||||
|
||||
} // if
|
||||
|
||||
// Delete all unused tags.
|
||||
|
||||
$missing_tag_font_query = db_select('fontyourface_tag', 't');
|
||||
$tag_font_alias = $missing_tag_font_query->leftJoin('fontyourface_tag_font', 'tf', 'tf.tid = t.tid');
|
||||
$missing_tags = $missing_tag_font_query
|
||||
->isNull($tag_font_alias . '.fid')
|
||||
->fields('t', array('tid'))
|
||||
->execute();
|
||||
|
||||
$missing_tids = array();
|
||||
|
||||
foreach ($missing_tags as $missing_tag) {
|
||||
$missing_tids[] = $missing_tag->tid;
|
||||
} // foreach
|
||||
|
||||
if (count($missing_tids) > 0) {
|
||||
|
||||
db_delete('fontyourface_tag')
|
||||
->condition('tid', $missing_tids, 'IN')
|
||||
->execute();
|
||||
|
||||
} // if
|
||||
|
||||
} // fontyourface_delete_unused_tags
|
||||
|
||||
/**
|
||||
* Logs to watchdog if logging is enabled.
|
||||
*
|
||||
* @param string $message
|
||||
* Log message. This should be a literal string; see
|
||||
* http://drupal.org/node/323101 for more details.
|
||||
* @param array $arguments
|
||||
* Arguments to replace placeholders, if there are any, in $message.
|
||||
*/
|
||||
function fontyourface_log($message, $arguments) {
|
||||
|
||||
if (variable_get('fontyourface_detailed_logging', FALSE)) {
|
||||
watchdog('@font-your-face', $message, $arguments, WATCHDOG_INFO);
|
||||
} // if
|
||||
|
||||
} // fontyourface_log
|
||||
|
||||
/**
|
||||
* Parse the info file of the currently used theme
|
||||
*/
|
||||
function fontyourface_parse_theme_info_file() {
|
||||
|
||||
$font_declarations = array();
|
||||
|
||||
$theme_default = variable_get('theme_default', 'bartik');
|
||||
$info = drupal_parse_info_file(drupal_get_path('theme', $theme_default) . '/' . $theme_default . '.info');
|
||||
|
||||
if (isset($info['fonts'])) {
|
||||
$font_declarations = $info['fonts'];
|
||||
} // if
|
||||
|
||||
return $font_declarations;
|
||||
|
||||
} // fontyourface_parse_theme_info_file
|
||||
|
||||
/**
|
||||
* Implements hook_ajax_render_alter().
|
||||
* Adds CSS for fonts loaded via AJAX.
|
||||
*/
|
||||
function fontyourface_ajax_render_alter(&$commands) {
|
||||
|
||||
// Clear out any non-font CSS so it doesn't get re-added.
|
||||
|
||||
drupal_static_reset('drupal_add_css');
|
||||
|
||||
// Get all the CSS that would otherwise be added in preprocess_html functions.
|
||||
|
||||
$vars = array();
|
||||
|
||||
fontyourface_preprocess_html($vars);
|
||||
|
||||
foreach (module_implements('fontyourface_info') as $provider) {
|
||||
|
||||
$function = $provider . '_preprocess_html';
|
||||
|
||||
if (function_exists($function)) {
|
||||
$function($vars);
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
// Add AJAX command to prepend the CSS to <head>.
|
||||
|
||||
if (isset($vars['styles'])) {
|
||||
$commands[] = ajax_command_prepend('head', $vars['styles']);
|
||||
} // if
|
||||
|
||||
} // fontyourface_ajax_render_alter
|
102
sites/all/modules/fontyourface/fontyourface.test
Normal file
102
sites/all/modules/fontyourface/fontyourface.test
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides tests for simpletest.
|
||||
*/
|
||||
|
||||
class FontyourfaceSaveFontTestCase extends DrupalWebTestCase {
|
||||
|
||||
public function getInfo() {
|
||||
|
||||
return array(
|
||||
'name' => t('Save font'),
|
||||
'description' => t('Saves new font and updates existing font.'),
|
||||
'group' => t('@font-your-face'),
|
||||
);
|
||||
|
||||
} // getInfo
|
||||
|
||||
public function setUp() {
|
||||
|
||||
parent::setUp('fontyourface');
|
||||
|
||||
} // setUp
|
||||
|
||||
public function test() {
|
||||
|
||||
// Save font.
|
||||
|
||||
$best_font_ever = new stdClass;
|
||||
$best_font_ever->name = 'Best Font Ever';
|
||||
$best_font_ever->url = 'http://www.bestfontever.com/';
|
||||
$best_font_ever->provider = 'best_font_provider';
|
||||
$best_font_ever->css_family = 'best-font-ever';
|
||||
$best_font_ever->foundry = 'Best Foundry';
|
||||
$best_font_ever->license = 'Best License Agreement';
|
||||
$best_font_ever->license_url = 'http://www.bestfontever.com/license.html';
|
||||
$best_font_ever->tags = array('sans-serif', 'best');
|
||||
|
||||
fontyourface_save_font($best_font_ever);
|
||||
|
||||
// Check a font is inserted.
|
||||
|
||||
$fids = array();
|
||||
$results = db_query('SELECT fid FROM {fontyourface_font}');
|
||||
|
||||
while ($result = $results->fetchObject()) {
|
||||
$fids[] = $result->fid;
|
||||
} // while
|
||||
|
||||
$this->assertIdentical(count($fids), 1, '1 fid in database.');
|
||||
|
||||
// Check font loads.
|
||||
|
||||
$font = fontyourface_get_font($fids[0], TRUE);
|
||||
|
||||
$this->assertTrue($font, 'Font loaded.');
|
||||
|
||||
// Check font matches.
|
||||
|
||||
$this->assertIdentical($font->name, $best_font_ever->name, 'Font name matches insert.');
|
||||
$this->assertIdentical($font->fid, $best_font_ever->fid, 'Font fid matches insert.');
|
||||
|
||||
// Save update.
|
||||
|
||||
$updated_best_font_ever = new stdClass;
|
||||
$updated_best_font_ever->name = 'Updated Best Font Ever';
|
||||
$updated_best_font_ever->url = 'http://www.bestfontever.com/';
|
||||
$updated_best_font_ever->provider = 'best_font_provider';
|
||||
$updated_best_font_ever->css_family = 'updated-best-font-ever';
|
||||
$updated_best_font_ever->foundry = 'Best Foundry';
|
||||
$updated_best_font_ever->license = 'Best License Agreement';
|
||||
$updated_best_font_ever->license_url = 'http://www.bestfontever.com/license.html';
|
||||
$updated_best_font_ever->tags = array('sans-serif', 'best', 'updated');
|
||||
|
||||
fontyourface_save_font($updated_best_font_ever);
|
||||
|
||||
// Check font was not inserted.
|
||||
|
||||
$fids = array();
|
||||
$results = db_query('SELECT fid FROM {fontyourface_font}');
|
||||
|
||||
while ($result = $results->fetchObject()) {
|
||||
$fids[] = $result->fid;
|
||||
} // while
|
||||
|
||||
$this->assertIdentical(count($fids), 1, 'Still 1 fid in database.');
|
||||
|
||||
// Check font loads.
|
||||
|
||||
$font = fontyourface_get_font($fids[0], TRUE);
|
||||
|
||||
$this->assertTrue($font, 'Font loaded again.');
|
||||
|
||||
// Check font matches.
|
||||
|
||||
$this->assertIdentical($font->name, $updated_best_font_ever->name, 'Font name matches update.');
|
||||
$this->assertIdentical($font->fid, $updated_best_font_ever->fid, 'Font fid matches update.');
|
||||
|
||||
} // test
|
||||
|
||||
} // FontyourfaceSaveFontTestCase
|
49
sites/all/modules/fontyourface/modules/edge_fonts/README.txt
Normal file
49
sites/all/modules/fontyourface/modules/edge_fonts/README.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
Edge Fonts (edge_fonts) module
|
||||
|
||||
SUMMARY
|
||||
|
||||
This module lets you use Adobe® Edge Web Fonts (http://www.edgefonts.com/).
|
||||
|
||||
PREREQUISITES
|
||||
|
||||
Edge Fonts depends on @font-your-face (http://drupal.org/project/fontyourface).
|
||||
|
||||
CONFIGURATION
|
||||
|
||||
-- SCRIPT URLS
|
||||
|
||||
Adobe recommends fonts to be requested using schema-less URLs (e.g.,
|
||||
//use.edgefonts.net/ubuntu.js); if that does not work for you, you can choose
|
||||
to use HTTP/HTTPS explicitly.
|
||||
(See http://www.edgefonts.com/#protocol)
|
||||
|
||||
-- SUBSETS TO USE
|
||||
|
||||
There are two options: 'default', which, as per Adobe, "contains the Latin-1
|
||||
character set plus useful typographic marks", and 'all', which "contains every
|
||||
glyph that’s available in the original font". The former results in smaller
|
||||
files and hence is likely to have slightly better performace, while the latter
|
||||
will contain any extended characters if available.
|
||||
(See http://www.edgefonts.com/#subsets)
|
||||
|
||||
KNOWN ISSUES
|
||||
|
||||
Edge Fonts do not work in Midori (http://twotoasts.de/index.php/midori/)
|
||||
browser. This seems to be an issue somewhere between Midori and Adobe, not with
|
||||
this module or @font-your-face.
|
||||
|
||||
MISCELLANEOUS INFORMATION
|
||||
|
||||
-- AVAILABLE FONTS
|
||||
|
||||
As of October 2012, there were 862 fonts of 501 families available (see
|
||||
http://www.edgefonts.com/#list-of-available-fonts). There is yet no API to
|
||||
provide information on available fonts, so a list is hard-coded into the
|
||||
module. If you notice that the list on Adobe's site has changed, file an issue,
|
||||
and we will update the module accordingly.
|
||||
|
||||
-- FONT URLS
|
||||
|
||||
Edge Fonts does not have an individual page or URL for each font; therefore,
|
||||
font URLs point to the available font list, and '?font=' is just a pseudo-
|
||||
parameter that allows URLs to be unique.
|
@@ -0,0 +1,12 @@
|
||||
name = Edge Fonts
|
||||
description = @font-your-face provider for Edge Fonts.
|
||||
dependencies[] = fontyourface
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install/uninstall tasks for the Edge Fonts module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function edge_fonts_enable() {
|
||||
// Set weight to 1 to ensure edge_fonts_preprocess_html() is executed after
|
||||
// fontyourface_preprocess_html(), which has weight of 0.
|
||||
db_update('system')
|
||||
->fields(array('weight' => 1))
|
||||
->condition('name', 'edge_fonts')
|
||||
->execute();
|
||||
// Import/update fonts.
|
||||
fontyourface_import_fonts('edge_fonts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function edge_fonts_disable() {
|
||||
fontyourface_provider_disable('edge_fonts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function edge_fonts_uninstall() {
|
||||
variable_del('edge_fonts_base');
|
||||
variable_del('edge_fonts_subsets');
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Edge Fonts module main file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_info().
|
||||
*/
|
||||
function edge_fonts_fontyourface_info() {
|
||||
return array(
|
||||
'name' => 'Edge Fonts',
|
||||
'url' => 'http://www.edgefonts.com/',
|
||||
'base_path' => 'http://www.edgefonts.com/?font=',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_import().
|
||||
*/
|
||||
function edge_fonts_fontyourface_import() {
|
||||
include_once 'edge_fonts.list.inc';
|
||||
// Get available fonts.
|
||||
$families = edge_fonts_list();
|
||||
$variants = 0;
|
||||
foreach ($families as $family_name => $family) {
|
||||
foreach ($family['variants'] as $variant => $variant_name) {
|
||||
$font = new stdClass();
|
||||
$font->provider = 'edge_fonts';
|
||||
$font->name = $family['fontname'] . ' ' . $variant_name;
|
||||
$font->css_family = $family_name;
|
||||
$font->css_weight = $variant[1] . '00';
|
||||
if ($variant[0] == 'i') {
|
||||
$font->css_style = 'italic';
|
||||
}
|
||||
$metadata = array(
|
||||
'variant' => $variant,
|
||||
);
|
||||
$font->metadata = serialize($metadata);
|
||||
$font->url = 'http://www.edgefonts.com/?font=' . $family_name . ':' . $variant . '#list-of-available-fonts';
|
||||
$font->license = 'Terms of Use';
|
||||
$font->license_url = 'http://www.edgefonts.com/#terms';
|
||||
fontyourface_save_font($font);
|
||||
$variants++;
|
||||
}
|
||||
}
|
||||
drupal_set_message(t('!fonts Edge Fonts of !families families imported/updated.', array('!fonts' => $variants, '!families' => count($families))));
|
||||
fontyourface_log('!fonts Edge Fonts of !families families imported/updated.', array('!fonts' => $variants, '!families' => count($families)));
|
||||
// Return TRUE if we succeeded in importing something, FALSE if not.
|
||||
return (bool) count($families);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements template_preprocess_html().
|
||||
*/
|
||||
function edge_fonts_preprocess_html(&$vars) {
|
||||
if (!empty($vars['fontyourface'])) {
|
||||
$fonts = array();
|
||||
foreach ($vars['fontyourface'] as $active_font) {
|
||||
if ($active_font->provider == 'edge_fonts') {
|
||||
$metadata = unserialize($active_font->metadata);
|
||||
$fonts[$active_font->css_family][] = $metadata['variant'];
|
||||
}
|
||||
}
|
||||
if (count($fonts) > 0) {
|
||||
if (variable_get('edge_fonts_base', 'naked') == 'naked') {
|
||||
$base = '//use.edgefonts.net/';
|
||||
}
|
||||
elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||
$base = 'https://use.edgefonts.net/';
|
||||
}
|
||||
else {
|
||||
$base = 'http://use.edgefonts.net/';
|
||||
}
|
||||
$families = array();
|
||||
$all_subsets = (variable_get('edge_fonts_subsets', 'default') == 'all') ? ':all' : '';
|
||||
foreach ($fonts as $family => $variants) {
|
||||
$families[] = $family . ':' . implode(',', $variants) . $all_subsets;
|
||||
}
|
||||
$js = $base . implode(';', $families) . '.js';
|
||||
drupal_add_js($js, array('type' => 'external'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_preview().
|
||||
*/
|
||||
function edge_fonts_fontyourface_preview($font, $text = NULL, $size = 18) {
|
||||
$output = '';
|
||||
if ($text == NULL) {
|
||||
$text = $font->name;
|
||||
}
|
||||
if ($size == 'all') {
|
||||
// Display variety of sizes.
|
||||
$sizes = array(32, 24, 18, 14, 12, 10);
|
||||
foreach ($sizes as $size) {
|
||||
$output .= '<div style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</div>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Display single size.
|
||||
$output = '<span style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</span>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function edge_fonts_form_fontyourface_ui_settings_form_alter(&$form, &$form_state, $form_id) {
|
||||
$form['edge_fonts'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Edge Fonts',
|
||||
'#weight' => -1,
|
||||
'edge_fonts_base' => array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Script URLs'),
|
||||
'#options' => array(
|
||||
'naked' => t('// (schema-less - recommended by the provider)'),
|
||||
'http' => t('http:// or https:// (ask the server)'),
|
||||
),
|
||||
'#default_value' => variable_get('edge_fonts_base', 'naked'),
|
||||
),
|
||||
'edge_fonts_subsets' => array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Subsets to use'),
|
||||
'#options' => array(
|
||||
'default' => t('Default'),
|
||||
'all' => t('All'),
|
||||
),
|
||||
'#default_value' => variable_get('edge_fonts_subsets', 'default'),
|
||||
),
|
||||
'edge_fonts_save_settings' => array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save settings'),
|
||||
),
|
||||
);
|
||||
$form['#submit'][] = 'edge_fonts_save_settings';
|
||||
// Move the default update/import button to the Edge Fonts fieldset.
|
||||
if (isset($form['providers']['edge_fonts_import'])) {
|
||||
$form['edge_fonts']['edge_fonts_import'] = $form['providers']['edge_fonts_import'];
|
||||
unset($form['providers']['edge_fonts_import']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom submit handler for fontyourface_ui_settings_form.
|
||||
*/
|
||||
function edge_fonts_save_settings($form, &$form_state) {
|
||||
if ($form_state['clicked_button']['#parents'][0] == 'edge_fonts_save_settings') {
|
||||
variable_set('edge_fonts_base', $form_state['values']['edge_fonts_base']);
|
||||
variable_set('edge_fonts_subsets', $form_state['values']['edge_fonts_subsets']);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
name = Edge Fonts Scraper
|
||||
description = Scrapes font info from edgefonts.com
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Edge Fonts scraper - gets font info from www.edgefonts.com.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function edge_fonts_scraper_menu() {
|
||||
$items['ef_scraper'] = array(
|
||||
'title' => 'EF Scraper',
|
||||
'page callback' => 'edge_fonts_scraper_do',
|
||||
'access callback' => TRUE,
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page callback for 'ef_scraper'.
|
||||
*/
|
||||
function edge_fonts_scraper_do() {
|
||||
$raw = drupal_http_request('http://www.edgefonts.com/');
|
||||
$return = $raw->data;
|
||||
|
||||
$current = 0;
|
||||
$counter = 0;
|
||||
|
||||
while (strpos($return, '<table>', $current) > 0) {
|
||||
|
||||
$start = strpos($return, '<table>', $current);
|
||||
$end = strpos($return, '</table>', $start);
|
||||
$portion = substr($return, $start, $end - $start);
|
||||
$current = $end;
|
||||
|
||||
$start = strpos($portion, '<th>');
|
||||
$end = strpos($portion, '</th>', $start);
|
||||
$name = strip_tags(substr($portion, $start, $end - $start));
|
||||
|
||||
$start = strpos($portion, '<code>');
|
||||
$end = strpos($portion, '</code>', $start);
|
||||
$fname = strip_tags(substr($portion, $start, $end - $start));
|
||||
$current2 = $end;
|
||||
|
||||
$variants = array();
|
||||
while (strpos($portion, '<th>', $current2) > 0) {
|
||||
$start = strpos($portion, '<th>', $current2);
|
||||
$end = strpos($portion, '</th>', $start);
|
||||
$vname = strip_tags(substr($portion, $start, $end - $start));
|
||||
$current2 = $end;
|
||||
|
||||
$start = strpos($portion, '<code>', $current2);
|
||||
$end = strpos($portion, '</code>', $start);
|
||||
$vcode = strip_tags(substr($portion, $start, $end - $start));
|
||||
if (!empty($variants[$vcode])) {
|
||||
drupal_set_message(t('Duplicate variant code in %font!', array('%font' => $name)), 'warning');
|
||||
}
|
||||
else {
|
||||
$variants[$vcode] = $vname;
|
||||
$counter++;
|
||||
}
|
||||
$current2 = $end;
|
||||
}
|
||||
|
||||
$arr[$fname] = array('fontname' => $name, 'variants' => $variants);
|
||||
}
|
||||
|
||||
$out = edge_fonts_scraper_drupalcs(var_export($arr, TRUE), 2);
|
||||
|
||||
drupal_set_message(t('!fonts Edge Fonts of !families families scraped.', array('!fonts' => $counter, '!families' => count($arr))));
|
||||
return '<pre>' . $out . '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function - rewrite var_export() to Drupal coding standards.
|
||||
*
|
||||
* We are probably reinventing the bicycle here.
|
||||
*/
|
||||
function edge_fonts_scraper_drupalcs($export, $indent = 0) {
|
||||
$step1 = str_replace('array (', 'array(', $export);
|
||||
$step2 = str_replace("=> \n", '=> ', $step1);
|
||||
$step3 = preg_replace('/=>\s\s+/', '=> ', $step2);
|
||||
if ($indent > 0) {
|
||||
foreach (explode("\n", $step3) as $line) {
|
||||
$tmp[] = str_repeat(' ', $indent) . $line;
|
||||
}
|
||||
$step4 = implode("\n", $tmp);
|
||||
}
|
||||
else {
|
||||
$step4 = $step3;
|
||||
}
|
||||
return $step4;
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
name = Font Reference
|
||||
description = Defines a field type for referencing a font from a node.
|
||||
package = Fields
|
||||
core = 7.x
|
||||
dependencies[] = fontyourface
|
||||
dependencies[] = field
|
||||
dependencies[] = options
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Defines a field type for referencing a font from a node.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_info().
|
||||
*/
|
||||
function font_reference_field_info() {
|
||||
|
||||
return array(
|
||||
'font_reference' => array(
|
||||
'label' => t('Font reference'),
|
||||
'description' => t('This field stores the ID of a related font as an integer value.'),
|
||||
'settings' => array('css_selector' => ''),
|
||||
'default_widget' => 'options_select',
|
||||
'default_formatter' => 'font_reference_default',
|
||||
),
|
||||
);
|
||||
|
||||
} // font_reference_field_info
|
||||
|
||||
/**
|
||||
* Implements hook_field_schema();
|
||||
*/
|
||||
function font_reference_field_schema($field) {
|
||||
|
||||
return array(
|
||||
'columns' => array(
|
||||
'fid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
),
|
||||
'indexes' => array('fid' => array('fid')),
|
||||
'foreign keys' => array(
|
||||
'fid' => array(
|
||||
'table' => 'fontyourface_font',
|
||||
'columns' => array('fid' => 'fid'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
} // font_reference_field_schema
|
||||
|
||||
/**
|
||||
* Implements hook_field_settings_form().
|
||||
*/
|
||||
function font_reference_field_settings_form($field, $instance, $has_data) {
|
||||
|
||||
$settings = $field['settings'];
|
||||
|
||||
$form = array();
|
||||
$form['css_selector'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Applied CSS selector'),
|
||||
'#default_value' => $settings['css_selector'],
|
||||
);
|
||||
return $form;
|
||||
|
||||
} // font_reference_field_settings_form
|
||||
|
||||
/**
|
||||
* Implements hook_field_validate().
|
||||
*/
|
||||
function font_reference_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
|
||||
|
||||
$ids = array();
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
|
||||
if (is_array($item) && !empty($item['fid'])) {
|
||||
|
||||
if (is_numeric($item['fid'])) {
|
||||
$ids[] = $item['fid'];
|
||||
} // if
|
||||
else {
|
||||
$errors[$field['field_name']][$langcode][$delta][] = array(
|
||||
'error' => 'invalid_fid',
|
||||
'message' => t('%name: invalid input.',
|
||||
array('%name' => $instance['label'])),
|
||||
);
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
if ($ids) {
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
|
||||
if (
|
||||
(is_array($item)) &&
|
||||
(!empty($item['fid']))
|
||||
) {
|
||||
|
||||
$font_exists = db_query_range("SELECT fid FROM {fontyourface_font} WHERE fid = :fid", 0, 1, array(':fid' => $item['fid']))->fetchObject();
|
||||
|
||||
if (!$font_exists) {
|
||||
|
||||
$errors[$field['field_name']][$langcode][$delta][] = array(
|
||||
'error' => 'invalid_fid',
|
||||
'message' => t("%name: this font can't be referenced.",
|
||||
array('%name' => $instance['label'])),
|
||||
);
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
|
||||
} // font_reference_field_validate
|
||||
|
||||
/**
|
||||
* Implements hook_field_is_empty().
|
||||
*/
|
||||
function font_reference_field_is_empty($item, $field) {
|
||||
|
||||
return empty($item['fid']);
|
||||
|
||||
} // font_reference_field_is_empty
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_info().
|
||||
*/
|
||||
function font_reference_field_formatter_info() {
|
||||
|
||||
return array(
|
||||
'font_reference_default' => array(
|
||||
'label' => t('Default'),
|
||||
'description' => t("Apply the font in CSS, display nothing."),
|
||||
'field types' => array('font_reference'),
|
||||
),
|
||||
'font_reference_name' => array(
|
||||
'label' => t('Name'),
|
||||
'description' => t("Display the name of the referenced font."),
|
||||
'field types' => array('font_reference'),
|
||||
),
|
||||
);
|
||||
|
||||
} // font_reference_field_formatter_info
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*/
|
||||
function font_reference_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
||||
|
||||
$result = array();
|
||||
|
||||
switch ($display['type']) {
|
||||
|
||||
case 'font_reference_default':
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
|
||||
if ($field['settings']['css_selector'] != '') {
|
||||
|
||||
$font = fontyourface_get_font($item['fid']);
|
||||
|
||||
$css = $field['settings']['css_selector'] . ' { ' . fontyourface_font_css($font) . ' }';
|
||||
|
||||
drupal_add_css($css, array('type' => 'inline'));
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
break;
|
||||
|
||||
case 'font_reference_name':
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
|
||||
$font = fontyourface_get_font($item['fid']);
|
||||
|
||||
$result[$delta] = array(
|
||||
'#markup' => check_plain($font->name),
|
||||
);
|
||||
|
||||
if ($field['settings']['css_selector'] != '') {
|
||||
|
||||
$css = $field['settings']['css_selector'] . ' { ' . fontyourface_font_css($font) . ' }';
|
||||
|
||||
drupal_add_css($css, array('type' => 'inline'));
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
break;
|
||||
|
||||
} // switch
|
||||
|
||||
return $result;
|
||||
|
||||
} // font_reference_field_formatter_view
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_info_alter().
|
||||
*/
|
||||
function font_reference_field_widget_info_alter(&$info) {
|
||||
|
||||
$info['options_select']['field types'][] = 'font_reference';
|
||||
|
||||
} // font_reference_field_widget_info_alter
|
||||
|
||||
/**
|
||||
* Implements hook_options_list().
|
||||
*/
|
||||
function font_reference_options_list($field) {
|
||||
|
||||
$function = !empty($field['settings']['options_list_callback']) ? $field['settings']['options_list_callback'] : 'font_reference_allowed_values';
|
||||
|
||||
return $function($field);
|
||||
|
||||
} // font_reference_options_list
|
||||
|
||||
/**
|
||||
* Returns list of enabled fonts.
|
||||
*/
|
||||
function font_reference_allowed_values($field) {
|
||||
|
||||
$fonts = fontyourface_get_fonts();
|
||||
|
||||
$options = array();
|
||||
|
||||
foreach ($fonts as $font) {
|
||||
$options[$font->fid] = check_plain($font->name);
|
||||
} // foreach
|
||||
|
||||
return $options;
|
||||
|
||||
} // font_reference_allowed_values
|
@@ -0,0 +1,16 @@
|
||||
name = Fontdeck
|
||||
description = @font-your-face provider of fonts from Fontdeck.com.
|
||||
dependencies[] = fontyourface
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
php = 5.2.0
|
||||
|
||||
files[] = fontdeck.install
|
||||
files[] = fontdeck.module
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Removes fonts on disable.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function fontdeck_enable() {
|
||||
|
||||
// Set weight to 1 to ensure fontdeck_preprocess_html() is executed after
|
||||
// fontyourface_preprocess_html(), which has weight of 0.
|
||||
db_update('system')
|
||||
->fields(array('weight' => 1))
|
||||
->condition('name', 'fontdeck')
|
||||
->execute();
|
||||
|
||||
} // fontdeck_enable
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function fontdeck_disable() {
|
||||
|
||||
fontyourface_provider_disable('fontdeck');
|
||||
|
||||
} // fontdeck_disable
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function fontdeck_uninstall() {
|
||||
|
||||
variable_del('fontdeck_project');
|
||||
variable_del('fontdeck_css');
|
||||
|
||||
} // fontdeck_uninstall
|
226
sites/all/modules/fontyourface/modules/fontdeck/fontdeck.module
Normal file
226
sites/all/modules/fontyourface/modules/fontdeck/fontdeck.module
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
define('FONTDECK_BASE_URL', 'http://fontdeck.com/api/v1/');
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_info().
|
||||
*/
|
||||
function fontdeck_fontyourface_info() {
|
||||
|
||||
return array(
|
||||
'name' => 'Fontdeck',
|
||||
'url' => 'http://fontdeck.com/',
|
||||
'base_path' => 'http://fontdeck.com/search?q=',
|
||||
);
|
||||
|
||||
return $info;
|
||||
|
||||
} // fontdeck_fontyourface_info
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_import().
|
||||
*/
|
||||
function fontdeck_fontyourface_import() {
|
||||
|
||||
$success = TRUE;
|
||||
$project = variable_get('fontdeck_project', '');
|
||||
$domain = fontdeck_get_domain();
|
||||
|
||||
$project_info_url = FONTDECK_BASE_URL . 'project-info?project=' . $project . '&domain=' . $domain;
|
||||
|
||||
if ($project != '') {
|
||||
|
||||
$response = drupal_http_request($project_info_url);
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if (isset($data->error)) {
|
||||
drupal_set_message($data->error, 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
$fontdeck_css = variable_get('fontdeck_css', array());
|
||||
|
||||
if (!isset($fontdeck_css[$project])) {
|
||||
$fontdeck_css[$project] = array();
|
||||
} // if
|
||||
|
||||
$fontdeck_css[$project][$domain] = $data->css;
|
||||
|
||||
variable_set('fontdeck_css', $fontdeck_css);
|
||||
|
||||
foreach ($data->provides as $import_font) {
|
||||
|
||||
$font = new StdClass;
|
||||
$font->name = $import_font->name;
|
||||
$font->url = 'http://fontdeck.com/search?q=' . urlencode($import_font->name);
|
||||
$font->provider = 'fontdeck';
|
||||
$font->tags = array();
|
||||
$font->css_family = $import_font->name;
|
||||
$font->css_style = $import_font->style;
|
||||
$font->css_weight = $import_font->weight;
|
||||
|
||||
fontyourface_save_font($font);
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
$success = FALSE;
|
||||
drupal_set_message(t('There was an error importing font information for project @project on this domain (@domain) from Fontdeck.', array('@project' => $project, '@domain' => $domain)), 'error');
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
$success = FALSE;
|
||||
drupal_set_message(t('Missing project number to import.'), 'error');
|
||||
|
||||
} // else
|
||||
|
||||
return $success;
|
||||
|
||||
} // fontdeck_fontyourface_import
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function fontdeck_form_alter(&$form, &$form_state, $form_id) {
|
||||
|
||||
if ($form_id == 'fontyourface_ui_settings_form') {
|
||||
|
||||
$form['fontdeck'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Fontdeck',
|
||||
'#weight' => -1,
|
||||
'fontdeck_project' => array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Fontdeck project number'),
|
||||
'#description' => t('Only paste the project number part in the URL.'),
|
||||
'#default_value' => variable_get('fontdeck_project', ''),
|
||||
'#field_prefix' => t('http://fontdeck.com/project/'),
|
||||
'#size' => 10,
|
||||
),
|
||||
'fontdeck_project_save' => array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save project number'),
|
||||
),
|
||||
);
|
||||
|
||||
// Move the default update/import button to the Fontdeck fieldset
|
||||
if (isset($form['providers']['fontdeck_import'])) {
|
||||
$form['fontdeck']['fontdeck_import'] = $form['providers']['fontdeck_import'];
|
||||
unset($form['providers']['fontdeck_import']);
|
||||
}
|
||||
|
||||
$form['#submit'][] = 'fontdeck_project_submit';
|
||||
|
||||
} // if
|
||||
|
||||
} // fontdeck_form_alter
|
||||
|
||||
/**
|
||||
* Updates project number.
|
||||
*/
|
||||
function fontdeck_project_submit($form, &$form_state) {
|
||||
|
||||
if ($form_state['clicked_button']['#parents'][0] == 'fontdeck_project_save') {
|
||||
|
||||
variable_set('fontdeck_project', $form_state['values']['fontdeck_project']);
|
||||
drupal_set_message(t('Fontdeck project updated.'));
|
||||
|
||||
} // if
|
||||
|
||||
} // fontdeck_project_submit
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_preview().
|
||||
*/
|
||||
function fontdeck_fontyourface_preview($font, $text = NULL, $size = 18) {
|
||||
|
||||
$output = '';
|
||||
|
||||
if ($text == NULL) {
|
||||
$text = $font->name;
|
||||
} // if
|
||||
|
||||
if ($size == 'all') {
|
||||
|
||||
// Display variety of sizes.
|
||||
|
||||
$sizes = array(32, 24, 18, 14, 12, 10);
|
||||
|
||||
foreach ($sizes as $size) {
|
||||
|
||||
$output .= '<div style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</div>';
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
// Display single size.
|
||||
|
||||
$output = '<span style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</span>';
|
||||
|
||||
} // else
|
||||
|
||||
return $output;
|
||||
|
||||
} // fontdeck_fontyourface_preview
|
||||
|
||||
/**
|
||||
* Implements template_preprocess_html().
|
||||
*/
|
||||
function fontdeck_preprocess_html(&$vars) {
|
||||
|
||||
$project = variable_get('fontdeck_project', '');
|
||||
$domain = fontdeck_get_domain();
|
||||
|
||||
if (!empty($vars['fontyourface']) && $project != '') {
|
||||
|
||||
$enabled_fonts = FALSE;
|
||||
|
||||
foreach ($vars['fontyourface'] as $used_font) {
|
||||
|
||||
if ($used_font->provider == 'fontdeck') {
|
||||
$enabled_fonts = TRUE;
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
if ($enabled_fonts) {
|
||||
|
||||
$fontdeck_css = variable_get('fontdeck_css', array());
|
||||
|
||||
if (isset($fontdeck_css[$project][$domain])) {
|
||||
|
||||
fontyourface_add_css_in_preprocess($vars, $fontdeck_css[$project][$domain], 'remote');
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
} // fontdeck_preprocess_html
|
||||
|
||||
/**
|
||||
* Helper function - gets the correct domain for authentication with Fontdeck.
|
||||
*/
|
||||
function fontdeck_get_domain() {
|
||||
|
||||
// We attempt to parse it as an URL, looking mainly to strip non-standard
|
||||
// port numbers. If it does not parse, it is obviously simple enought to be
|
||||
// used as it is.
|
||||
|
||||
$details = parse_url($_SERVER['HTTP_HOST']);
|
||||
$host = isset($details['host']) ? $details['host'] : $_SERVER['HTTP_HOST'];
|
||||
|
||||
return preg_replace('#^www.#', '', $host);
|
||||
|
||||
} // fontdeck_get_domain
|
800
sites/all/modules/fontyourface/modules/fonts_com/api.inc
Normal file
800
sites/all/modules/fontyourface/modules/fonts_com/api.inc
Normal file
@@ -0,0 +1,800 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* API functions.
|
||||
*/
|
||||
|
||||
define('FONTS_COM_API_BASE_URL', 'https://api.fonts.com');
|
||||
define('FONTS_COM_API_APP_KEY', '1fdb130c-d5c0-4fab-8e2b-271508570323932606');
|
||||
|
||||
/**
|
||||
* Gets list of fonts in a given project.
|
||||
*/
|
||||
function fonts_com_get_fonts_in_project($project_id) {
|
||||
|
||||
$fonts = array();
|
||||
|
||||
$path = '/rest/json/Fonts/?wfspstart=0&wfsplimit=100&wfspid=' . $project_id;
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path)));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if (isset($data->Fonts) && isset($data->Fonts->Font)) {
|
||||
|
||||
$font = $data->Fonts->Font;
|
||||
$fonts = fonts_com_unknown_to_array($font);
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error importing a project (@project) font list from Fonts.com.', array('@project' => $project_id)), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $fonts;
|
||||
|
||||
} // fonts_com_get_fonts_in_project
|
||||
|
||||
/**
|
||||
* Gets a list of all fonts, in given range.
|
||||
*/
|
||||
function fonts_com_get_all_fonts($start = 0, $limit = 100, $filters = array()) {
|
||||
|
||||
$result = array(
|
||||
'fonts' => array(),
|
||||
'count' => FALSE,
|
||||
);
|
||||
|
||||
if (
|
||||
(isset($filters['wfsfree'])) &&
|
||||
($filters['wfsfree'] == 0)
|
||||
) {
|
||||
$filters['wfsfree'] = 'true';
|
||||
} // if
|
||||
if (
|
||||
(isset($filters['wfsfree'])) &&
|
||||
($filters['wfsfree'] == -1)
|
||||
) {
|
||||
$filters['wfsfree'] = 'false';
|
||||
} // if
|
||||
|
||||
$query = array(
|
||||
'wfspstart' => $start,
|
||||
'wfsplimit' => $limit,
|
||||
) + $filters;
|
||||
|
||||
$path = '/rest/json/AllFonts/?' . drupal_http_build_query($query);
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path)));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
$font = $data->AllFonts->Font;
|
||||
$result['fonts'] = fonts_com_unknown_to_array($font);
|
||||
$result['count'] = intval($data->AllFonts->TotalRecords);
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error importing a font list from Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $result;
|
||||
|
||||
} // fonts_com_get_all_fonts
|
||||
|
||||
/**
|
||||
* Gets total font count.
|
||||
*/
|
||||
function fonts_com_get_all_fonts_count() {
|
||||
|
||||
$path = '/rest/json/AllFonts/?wfspstart=0&wfsplimit=1';
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path)));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
return $data->AllFonts->TotalRecords;
|
||||
|
||||
} // if
|
||||
|
||||
drupal_set_message(t('There was an error importing the font count from Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_get_all_fonts_count
|
||||
|
||||
/**
|
||||
* Gets auth key for a given account.
|
||||
*/
|
||||
function fonts_com_get_key_for_account($email, $password) {
|
||||
|
||||
$key = fonts_com_get_existing_key_for_account($email, $password);
|
||||
|
||||
if ($key) return $key;
|
||||
|
||||
$path = '/rest/json/Accounts/?wfsemail=' . $email;
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => array('AppKey' => FONTS_COM_API_APP_KEY, 'Password' => $password)));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if (
|
||||
isset($data->Accounts) &&
|
||||
isset($data->Accounts->Account) &&
|
||||
isset($data->Accounts->Account->AuthorizationKey)
|
||||
) {
|
||||
|
||||
$key = $data->Accounts->Account->AuthorizationKey;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('The submitted email and password were not recognized by Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error getting your key from Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $key;
|
||||
|
||||
} // fonts_com_get_key_for_account
|
||||
|
||||
/**
|
||||
* Gets auth key for a given account.
|
||||
*/
|
||||
function fonts_com_get_existing_key_for_account($email, $password) {
|
||||
|
||||
$path = '/rest/json/GetToken/?wfsemail=' . $email;
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => array('AppKey' => FONTS_COM_API_APP_KEY, 'Password' => $password)));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if (
|
||||
isset($data->Accounts) &&
|
||||
isset($data->Accounts->Account) &&
|
||||
isset($data->Accounts->Account->AuthorizationKey)
|
||||
) {
|
||||
|
||||
return $data->Accounts->Account->AuthorizationKey;
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_get_existing_key_for_account
|
||||
|
||||
/**
|
||||
* Creates a new account.
|
||||
*/
|
||||
function fonts_com_create_account($email, $first_name, $last_name) {
|
||||
|
||||
$success = FALSE;
|
||||
|
||||
$path = '/rest/json/Accounts/';
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => array('AppKey' => FONTS_COM_API_APP_KEY), 'method' => 'POST', 'data' => 'wfsfirst_name=' . $first_name . '&wfslast_name=' . $last_name . '&wfsemail=' . $email));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if (
|
||||
isset($data->Accounts) &&
|
||||
isset($data->Accounts->Message) &&
|
||||
($data->Accounts->Message == 'Success')
|
||||
) {
|
||||
|
||||
$success = TRUE;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('Fonts.com as unable to create your account.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error creating an account at Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $success;
|
||||
|
||||
} // fonts_com_create_account
|
||||
|
||||
/**
|
||||
* Gets list of domains in a given project.
|
||||
*/
|
||||
function fonts_com_get_domains_in_project($project_id) {
|
||||
|
||||
$domains = array();
|
||||
|
||||
$path = '/rest/json/Domains/?wfspstart=0&wfsplimit=100&wfspid=' . $project_id;
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path)));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if ($data->Domains->TotalRecords > 0) {
|
||||
|
||||
$domain = $data->Domains->Domain;
|
||||
$domains = fonts_com_unknown_to_array($domain);
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error importing a project (@project) domain list from Fonts.com.', array('@project' => $project_id)), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $domains;
|
||||
|
||||
} // fonts_com_get_domains_in_project
|
||||
|
||||
/**
|
||||
* Saves list of domains in a given project.
|
||||
*/
|
||||
function fonts_com_save_domains_in_project($project_id, $new_domains) {
|
||||
|
||||
$old_domains = array();
|
||||
$domain_to_index = array();
|
||||
|
||||
$old_domain_objects = fonts_com_get_domains_in_project($project_id);
|
||||
|
||||
foreach ($old_domain_objects as $index => $old_domain_object) {
|
||||
|
||||
$domain_to_index[$old_domain_object->DomainName] = $index;
|
||||
$old_domains[] = $old_domain_object->DomainName;
|
||||
|
||||
} // foreach
|
||||
|
||||
$add_domains = array_diff($new_domains, $old_domains);
|
||||
$delete_domains = array_diff($old_domains, $new_domains);
|
||||
|
||||
foreach ($delete_domains as $delete_domain) {
|
||||
|
||||
$delete_domain_object = $old_domain_objects[$domain_to_index[$delete_domain]];
|
||||
fonts_com_delete_domain($project_id, $delete_domain_object->DomainID);
|
||||
|
||||
} // foreach
|
||||
|
||||
foreach ($add_domains as $add_domain) {
|
||||
fonts_com_add_domain($project_id, $add_domain);
|
||||
} // foreach
|
||||
|
||||
fonts_com_publish();
|
||||
|
||||
} // fonts_com_save_domains_in_project
|
||||
|
||||
/**
|
||||
* Deletes a single domain in a project.
|
||||
*/
|
||||
function fonts_com_delete_domain($project_id, $domain_id) {
|
||||
|
||||
$path = '/rest/json/Domains/?wfspid=' . $project_id . '&wfsdomain_id=' . $domain_id;
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path), 'method' => 'DELETE'));
|
||||
|
||||
if ($response->code == 200) {
|
||||
return TRUE;
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error deleting a domain (@domain) in a project (@project) on Fonts.com.', array('@domain' => $domain_id, '@project' => $project_id)), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_delete_domain
|
||||
|
||||
/**
|
||||
* Adds a single domain to a project.
|
||||
*/
|
||||
function fonts_com_add_domain($project_id, $domain_name) {
|
||||
|
||||
$path = '/rest/json/Domains/?wfspid=' . $project_id;
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path), 'method' => 'POST', 'data' => 'wfsdomain_name=' . $domain_name));
|
||||
|
||||
if ($response->code == 200) {
|
||||
return TRUE;
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error adding a domain (@domain) in a project (@project) on Fonts.com.', array('@domain' => $domain_name, '@project' => $project_id)), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_add_domain
|
||||
|
||||
/**
|
||||
* Gets list of projects from API.
|
||||
*/
|
||||
function fonts_com_get_projects() {
|
||||
|
||||
$projects = array();
|
||||
|
||||
$path = '/rest/json/Projects/?wfspstart=0&wfsplimit=100';
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path)));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if ($data->Projects->TotalRecords > 0) {
|
||||
|
||||
$project = $data->Projects->Project;
|
||||
$projects = fonts_com_unknown_to_array($project);
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error importing project list from Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $projects;
|
||||
|
||||
} // fonts_com_get_projects
|
||||
|
||||
/**
|
||||
* Gets list of projects from API.
|
||||
*/
|
||||
function fonts_com_get_project_by_id($project_id) {
|
||||
|
||||
$projects = fonts_com_get_projects();
|
||||
|
||||
if (count($projects) > 0) {
|
||||
|
||||
foreach ($projects as $project) {
|
||||
|
||||
if ($project->ProjectKey == $project_id) {
|
||||
return $project;
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_get_project_by_id
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*/
|
||||
function fonts_com_save_project(&$project) {
|
||||
|
||||
$path = '/rest/json/Projects/';
|
||||
$method = 'POST';
|
||||
|
||||
if (isset($project->ProjectKey)) {
|
||||
|
||||
$path .= '?wfspid=' . $project->ProjectKey;
|
||||
$method = 'PUT';
|
||||
|
||||
} // if
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path), 'method' => $method, 'data' => 'wfsproject_name=' . $project->ProjectName));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
$projects = fonts_com_unknown_to_array($data->Projects->Project);
|
||||
|
||||
foreach ($projects as $response_project) {
|
||||
|
||||
if ($response_project->ProjectName == $project->ProjectName) {
|
||||
$project->ProjectKey = $response_project->ProjectKey;
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
return TRUE;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error saving project to Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_save_project
|
||||
|
||||
/**
|
||||
* Adds font to project.
|
||||
*/
|
||||
function fonts_com_add_font_to_project($font_id, $project_id) {
|
||||
|
||||
$path = '/rest/json/Fonts/?wfspid=' . $project_id;
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path), 'method' => 'POST', 'data' => 'wfsfid=' . $font_id));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
fonts_com_publish();
|
||||
return TRUE;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error enabling the font on Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_add_font_to_project
|
||||
|
||||
/**
|
||||
* Deletes font from project.
|
||||
*/
|
||||
function fonts_com_delete_font_from_project($font_id, $project_id) {
|
||||
|
||||
$path = '/rest/json/Fonts/?wfspid=' . $project_id . '&wfsfid=' . $font_id;
|
||||
|
||||
$response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array('headers' => fonts_com_api_headers($path), 'method' => 'DELETE'));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
fonts_com_publish();
|
||||
return TRUE;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error disabling the font on Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_delete_font_from_project
|
||||
|
||||
/**
|
||||
* Sets selector on font.
|
||||
*/
|
||||
function fonts_com_set_font_selector($project_id, $font_id, $selector) {
|
||||
|
||||
fonts_com_add_selector_to_project($project_id, $selector);
|
||||
$project_selectors = fonts_com_get_selectors_in_project($project_id);
|
||||
$selector_id = FALSE;
|
||||
|
||||
foreach ($project_selectors as $project_selector) {
|
||||
|
||||
if ($project_selector->SelectorTag == $selector) {
|
||||
$selector_id = $project_selector->SelectorID;
|
||||
} // if
|
||||
elseif ($project_selector->SelectorFontID == $font_id) {
|
||||
fonts_com_delete_selector_in_product($project_id, $project_selector->SelectorID);
|
||||
} // elseif
|
||||
|
||||
} // foreach
|
||||
|
||||
if ($selector_id) {
|
||||
|
||||
$path = '/rest/json/Selectors/?wfspid=' . $project_id;
|
||||
|
||||
$response = drupal_http_request(
|
||||
FONTS_COM_API_BASE_URL . $path,
|
||||
array(
|
||||
'headers' => fonts_com_api_headers($path),
|
||||
'method' => 'PUT',
|
||||
'data' => 'wfsselector_ids=' . $selector_id . '&wfsfont_ids=' . $font_id
|
||||
)
|
||||
);
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
fonts_com_publish();
|
||||
return TRUE;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error adding a CSS selector on Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_set_font_selector
|
||||
|
||||
/**
|
||||
* Removes selector from a project.
|
||||
*/
|
||||
function fonts_com_delete_selector_in_product($project_id, $selector_id) {
|
||||
|
||||
$path = '/rest/json/Selectors/?wfspid=' . $project_id . '&wfsselector_id=' . $selector_id . '&wfsnopublish=1';
|
||||
|
||||
$response = drupal_http_request(
|
||||
FONTS_COM_API_BASE_URL . $path,
|
||||
array(
|
||||
'headers' => fonts_com_api_headers($path),
|
||||
'method' => 'DELETE',
|
||||
)
|
||||
);
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
return TRUE;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error removing a CSS selector on Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_delete_selector_in_product
|
||||
|
||||
/**
|
||||
* Adds selector to project.
|
||||
*/
|
||||
function fonts_com_add_selector_to_project($project_id, $selector) {
|
||||
|
||||
$path = '/rest/json/Selectors/?wfspid=' . $project_id;
|
||||
|
||||
$response = drupal_http_request(
|
||||
FONTS_COM_API_BASE_URL . $path,
|
||||
array(
|
||||
'headers' => fonts_com_api_headers($path),
|
||||
'method' => 'POST',
|
||||
'data' => 'wfsselector_tag=' . urlencode($selector)
|
||||
)
|
||||
);
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
return TRUE;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error adding a CSS selector on Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // fonts_com_add_selector_to_project
|
||||
|
||||
/**
|
||||
* Gets selectors in project.
|
||||
*/
|
||||
function fonts_com_get_selectors_in_project($project_id) {
|
||||
|
||||
$selectors = array();
|
||||
|
||||
$path = '/rest/json/Selectors/?wfspid=' . $project_id;
|
||||
|
||||
$response = drupal_http_request(
|
||||
FONTS_COM_API_BASE_URL . $path,
|
||||
array(
|
||||
'headers' => fonts_com_api_headers($path),
|
||||
)
|
||||
);
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if (isset($data->Selectors) && isset($data->Selectors->Selector)) {
|
||||
|
||||
$selectors = fonts_com_unknown_to_array($data->Selectors->Selector);
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error adding a CSS selector on Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $selectors;
|
||||
|
||||
} // fonts_com_get_selectors_in_project
|
||||
|
||||
/**
|
||||
* Gets choices for filter.
|
||||
*/
|
||||
function fonts_com_get_filter_choices($filter) {
|
||||
|
||||
$choices = array();
|
||||
|
||||
$path = '/rest/json/FilterValues/?wfsfiltertype=' . $filter;
|
||||
|
||||
$response = drupal_http_request(
|
||||
FONTS_COM_API_BASE_URL . $path,
|
||||
array(
|
||||
'headers' => fonts_com_api_headers($path),
|
||||
)
|
||||
);
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if (isset($data->FilterValues) && isset($data->FilterValues->FilterValue)) {
|
||||
|
||||
$choices = fonts_com_unknown_to_array($data->FilterValues->FilterValue);
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error getting filter choices from Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $choices;
|
||||
|
||||
} // fonts_com_get_filter_choices
|
||||
|
||||
/**
|
||||
* Gets choices for all filter given current values.
|
||||
*/
|
||||
function fonts_com_get_all_filter_choices($current_filters) {
|
||||
|
||||
$path = '/rest/json/AllFilterValues/?' . drupal_http_build_query($current_filters);
|
||||
|
||||
$response = drupal_http_request(
|
||||
FONTS_COM_API_BASE_URL . $path,
|
||||
array(
|
||||
'headers' => fonts_com_api_headers($path),
|
||||
)
|
||||
);
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
|
||||
if (isset($data->FilterValues) && isset($data->FilterValues->FilterValue)) {
|
||||
|
||||
$choices = fonts_com_unknown_to_array($data->FilterValues->FilterValue);
|
||||
$choices_by_filter = array();
|
||||
|
||||
foreach ($choices as $choice) {
|
||||
|
||||
if (!isset($choices_by_filter[$choice->FilterType])) {
|
||||
$choices_by_filter[$choice->FilterType] = array();
|
||||
} // if
|
||||
|
||||
$choices_by_filter[$choice->FilterType][] = $choice;
|
||||
|
||||
} // foreach
|
||||
|
||||
return $choices_by_filter;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error getting filter choices from Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error getting filter choices from Fonts.com.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return array();
|
||||
|
||||
} // fonts_com_get_all_filter_choices
|
||||
|
||||
/**
|
||||
* Publishes changes.
|
||||
*/
|
||||
function fonts_com_publish() {
|
||||
|
||||
$path = '/rest/json/Publish/';
|
||||
|
||||
$response = drupal_http_request(
|
||||
FONTS_COM_API_BASE_URL . $path,
|
||||
array(
|
||||
'headers' => fonts_com_api_headers($path),
|
||||
)
|
||||
);
|
||||
|
||||
} // fonts_com_publish
|
||||
|
||||
/**
|
||||
* Provides headers with api parameters.
|
||||
*/
|
||||
function fonts_com_api_headers($path) {
|
||||
|
||||
$fonts_com_token = variable_get('fonts_com_token', '');
|
||||
|
||||
if (empty($fonts_com_token)) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
list($public_key, $private_key) = explode('--', $fonts_com_token);
|
||||
|
||||
$encoded = base64_encode(hash_hmac('md5', $public_key . '|' . $path, $private_key, TRUE));
|
||||
$auth = urlencode($public_key . ':' . $encoded);
|
||||
|
||||
return array('Authorization' => $auth, 'AppKey' => FONTS_COM_API_APP_KEY);
|
||||
|
||||
} // fonts_com_api_headers
|
||||
|
||||
/**
|
||||
* Returns an array, regardless of input.
|
||||
*/
|
||||
function fonts_com_unknown_to_array($unknown) {
|
||||
|
||||
if (is_array($unknown)) {
|
||||
return $unknown;
|
||||
} // if
|
||||
|
||||
return array($unknown);
|
||||
|
||||
} // fonts_com_unknown_to_array
|
@@ -0,0 +1,12 @@
|
||||
div.views-filter div.form-item {
|
||||
float: left;
|
||||
padding: .5em 1em 0 0;
|
||||
}
|
||||
|
||||
.view-content {
|
||||
clear: left;
|
||||
}
|
||||
|
||||
.form-submit {
|
||||
margin-top: 1.5em;
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
#fonts-com-setup-form .or {
|
||||
font-weight: bold;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
|
||||
#fonts-com-setup-form fieldset {
|
||||
margin: 0.5em 0;
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
name = Fonts.com
|
||||
description = @font-your-face provider of fonts from Fonts.com.
|
||||
dependencies[] = fontyourface
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
php = 5.2.0
|
||||
|
||||
files[] = api.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Removes fonts on disable.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function fonts_com_enable() {
|
||||
|
||||
// Set weight to 1 to ensure fonts_com_preprocess_html() is executed after
|
||||
// fontyourface_preprocess_html(), which has weight of 0.
|
||||
db_update('system')
|
||||
->fields(array('weight' => 1))
|
||||
->condition('name', 'fonts_com')
|
||||
->execute();
|
||||
|
||||
} // fonts_com_enable
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function fonts_com_disable() {
|
||||
|
||||
fontyourface_provider_disable('fonts_com');
|
||||
|
||||
} // fonts_com_disable
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function fonts_com_uninstall() {
|
||||
|
||||
variable_del('fonts_com_project');
|
||||
variable_del('fonts_com_filter_choices');
|
||||
variable_del('fonts_com_token');
|
||||
|
||||
} // fonts_com_uninstall
|
1431
sites/all/modules/fontyourface/modules/fonts_com/fonts_com.module
Normal file
1431
sites/all/modules/fontyourface/modules/fonts_com/fonts_com.module
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.fontsComProject = {
|
||||
|
||||
attach:function(context, settings) {
|
||||
|
||||
$('#edit-edit-project').hide();
|
||||
|
||||
if ($('#edit-project').val() != '') {
|
||||
$('#edit-project').change();
|
||||
} // if
|
||||
|
||||
} // attach
|
||||
|
||||
} // Drupal.behaviors.fontsComProject
|
||||
|
||||
})(jQuery);
|
@@ -0,0 +1,40 @@
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.fontsComSettings = {
|
||||
|
||||
attach:function(context, settings) {
|
||||
|
||||
$('#edit-auth a.fieldset-title').click(function() {
|
||||
|
||||
fontsComSettingsCollapse('#edit-pass');
|
||||
fontsComSettingsCollapse('#edit-create');
|
||||
|
||||
});
|
||||
|
||||
$('#edit-pass a.fieldset-title').click(function() {
|
||||
|
||||
fontsComSettingsCollapse('#edit-auth');
|
||||
fontsComSettingsCollapse('#edit-create');
|
||||
|
||||
});
|
||||
|
||||
$('#edit-create a.fieldset-title').click(function() {
|
||||
|
||||
fontsComSettingsCollapse('#edit-auth');
|
||||
fontsComSettingsCollapse('#edit-pass');
|
||||
|
||||
});
|
||||
|
||||
} // attach
|
||||
|
||||
} // Drupal.behaviors.fontsComSettings
|
||||
|
||||
function fontsComSettingsCollapse(id) {
|
||||
|
||||
if (!$(id).is('.collapsed')) {
|
||||
Drupal.toggleFieldset(id);
|
||||
} // if
|
||||
|
||||
} // fontsComSettingsCollapse
|
||||
|
||||
})(jQuery);
|
@@ -0,0 +1,12 @@
|
||||
name = Font Squirrel API
|
||||
description = @font-your-face provider with Font Squirrel fonts.
|
||||
dependencies[] = fontyourface
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
php = 5.2.0
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Removes fonts on disable.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function fontsquirrel_enable() {
|
||||
|
||||
// Set weight to 1 to ensure fontsquirrel_preprocess_html() is executed after
|
||||
// fontyourface_preprocess_html(), which has weight of 0.
|
||||
db_update('system')
|
||||
->fields(array('weight' => 1))
|
||||
->condition('name', 'fontsquirrel')
|
||||
->execute();
|
||||
|
||||
// Import/update fonts
|
||||
fontyourface_import_fonts('fontsquirrel');
|
||||
|
||||
} // fontsquirrel_enable
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function fontsquirrel_disable() {
|
||||
|
||||
fontyourface_provider_disable('fontsquirrel');
|
||||
|
||||
} // fontsquirrel_disable
|
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_info().
|
||||
*/
|
||||
function fontsquirrel_fontyourface_info() {
|
||||
|
||||
return array(
|
||||
'name' => 'Font Squirrel',
|
||||
'url' => 'http://www.fontsquirrel.com/',
|
||||
'base_path' => 'http://www.fontsquirrel.com/fonts/',
|
||||
);
|
||||
|
||||
} // fontsquirrel_fonts_api_fontyourface_info
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_preview().
|
||||
*/
|
||||
function fontsquirrel_fontyourface_preview($font, $text = NULL, $size = 18) {
|
||||
|
||||
$output = '';
|
||||
$metadata = unserialize($font->metadata);
|
||||
|
||||
if ($text == NULL) {
|
||||
$text = $font->name;
|
||||
} // if
|
||||
|
||||
if ($size == 'all') {
|
||||
|
||||
// Display variety of sizes.
|
||||
|
||||
$sizes = array(32, 24, 18, 14, 12, 10);
|
||||
|
||||
foreach ($sizes as $size) {
|
||||
|
||||
$output = '<img src="http://www.fontsquirrel.com/utils/makeFont.php?font=' . $metadata['id'] . '/' . $metadata['font_filename'] . '&width=300&size=' . $size . '&text=' . urlencode($text) . '" />';
|
||||
|
||||
} // foreach
|
||||
|
||||
$output .= '<div><img src="http://www.fontsquirrel.com/utils/makeSolotypeSample.php?font=' . $metadata['id'] . '/' . $metadata['font_filename'] . '&case=all" /></div>';
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
// Display single size.
|
||||
|
||||
$output = '<img src="http://www.fontsquirrel.com/utils/makeFont.php?font=' . $metadata['id'] . '/' . $metadata['font_filename'] . '&width=150&size=' . ($size - 10) . '&text=' . urlencode($text) . '" />';
|
||||
|
||||
} // else
|
||||
|
||||
return $output;
|
||||
|
||||
} // fontsquirrel_fontyourface_preview
|
||||
|
||||
/**
|
||||
* Implements template_preprocess_html().
|
||||
*/
|
||||
function fontsquirrel_preprocess_html(&$vars) {
|
||||
if (!empty($vars['fontyourface'])) {
|
||||
|
||||
$paths = array();
|
||||
|
||||
foreach ($vars['fontyourface'] as $used_font) {
|
||||
|
||||
if ($used_font->provider == 'fontsquirrel') {
|
||||
$metadata = unserialize($used_font->metadata);
|
||||
if (module_exists('google_webfont_loader_api') && !empty($used_font->css_family)) {
|
||||
$font_info = array(
|
||||
'custom_families' => array($used_font->css_family),
|
||||
'custom_style_css' => array('fontyourface/fontsquirrel/' . $metadata['path'] . '-fontfacekit/stylesheet.css'),
|
||||
);
|
||||
_google_webfont_loader_api_load_font($font_info);
|
||||
}
|
||||
else {
|
||||
$paths[] = $metadata['path'];
|
||||
}
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
if (count($paths) > 0) {
|
||||
|
||||
foreach ($paths as $path) {
|
||||
|
||||
fontyourface_add_css_in_preprocess($vars, 'fontyourface/fontsquirrel/' . $path . '-fontfacekit/stylesheet.css');
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
} // fontsquirrel_preprocess_html
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_enable().
|
||||
*/
|
||||
function fontsquirrel_fontyourface_enable($font) {
|
||||
|
||||
$success = TRUE;
|
||||
$metadata = unserialize($font->metadata);
|
||||
|
||||
if ($font->css_family == '') {
|
||||
|
||||
$api_result = drupal_http_request('http://www.fontsquirrel.com/api/familyinfo/' . $metadata['path']);
|
||||
|
||||
if ($api_result->code == '200') {
|
||||
|
||||
$decoded = json_decode($api_result->data);
|
||||
|
||||
if (is_array($decoded) && is_object($decoded[0])) {
|
||||
|
||||
$font->css_family = $decoded[0]->{'fontface_name'};
|
||||
fontyourface_save_font($font);
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error importing font information for %fontname from Font Squirrel. Font not found in API.', array('%fontname' => $font->name)), 'error');
|
||||
$success = FALSE;
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error importing font information for %fontname from Font Squirrel. API not responding.', array('%fontname' => $font-name)), 'error');
|
||||
$success = FALSE;
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
$directory_location = file_build_uri('fontyourface/fontsquirrel/' . $metadata['path'] . '-fontfacekit');
|
||||
|
||||
if (
|
||||
(!file_prepare_directory($directory_location))
|
||||
) {
|
||||
|
||||
$zip_location = file_build_uri('fontyourface/fontsquirrel/' . $metadata['path'] . '-fontfacekit.zip');
|
||||
|
||||
// Download file .zip file
|
||||
|
||||
if (!file_exists(drupal_realpath($zip_location))) {
|
||||
|
||||
$kit_url = 'http://www.fontsquirrel.com/fontfacekit/' . $metadata['path'];
|
||||
|
||||
$kit_result = drupal_http_request($kit_url);
|
||||
|
||||
if ($kit_result->code == 200) {
|
||||
|
||||
// Save the .zip file
|
||||
|
||||
$zip_location_directory = dirname($zip_location);
|
||||
|
||||
if (file_prepare_directory($zip_location_directory, FILE_CREATE_DIRECTORY)) {
|
||||
|
||||
file_unmanaged_save_data($kit_result->data, $zip_location, FILE_EXISTS_REPLACE);
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error saving font %fontname from Font Squirrel.', array('%fontname' => $font->name)), 'error');
|
||||
$success = FALSE;
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error downloading font %fontname from Font Squirrel.', array('%fontname' => $font->name)), 'error');
|
||||
$success = FALSE;
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
if ($success) {
|
||||
|
||||
// Unzip the .zip file
|
||||
|
||||
if (function_exists('zip_open') && $zip = zip_open(drupal_realpath($zip_location))) {
|
||||
|
||||
file_prepare_directory($directory_location, FILE_CREATE_DIRECTORY);
|
||||
|
||||
while ($entry = zip_read($zip)) {
|
||||
|
||||
if (zip_entry_open($zip, $entry, 'r') && ($zip_entry_filesize = zip_entry_filesize($entry))) {
|
||||
|
||||
$entry_name = zip_entry_name($entry);
|
||||
$data = zip_entry_read($entry, $zip_entry_filesize);
|
||||
file_unmanaged_save_data($data, $directory_location . '/' . $entry_name, FILE_EXISTS_REPLACE);
|
||||
|
||||
} // if
|
||||
|
||||
zip_entry_close($entry);
|
||||
|
||||
} // while
|
||||
|
||||
zip_close($zip);
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('Unable to unzip font %fontname at <code>@zip_location</code>. See !zipdocs to enable unzipping, or unzip the file manually and enable this font again.', array(
|
||||
'%fontname' => $font->name,
|
||||
'@zip_location' => $zip_location,
|
||||
'!zipdocs' => l(t('PHP documentation on zip'), 'http://www.php.net/manual/en/zip.installation.php'),
|
||||
)), 'error');
|
||||
$success = FALSE;
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
if (! $success) {
|
||||
fontyourface_disable_font($font);
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
return $success;
|
||||
|
||||
} // fontsquirrel_fontyourface_enable
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_import().
|
||||
*/
|
||||
function fontsquirrel_fontyourface_import() {
|
||||
|
||||
$families = array();
|
||||
|
||||
$api_result = drupal_http_request('http://www.fontsquirrel.com/api/fontlist/all');
|
||||
|
||||
if ($api_result->code == '200') {
|
||||
|
||||
$decoded = json_decode($api_result->data);
|
||||
|
||||
foreach ($decoded as $font_import) {
|
||||
|
||||
// If there are multiple variants, add to batch processing array.
|
||||
if ($font_import->family_count > 1) {
|
||||
$families[] = $font_import->family_urlname;
|
||||
}
|
||||
// If there is only one variant, save immediately.
|
||||
else {
|
||||
$metadata = array(
|
||||
'id' => $font_import->id,
|
||||
'path' => $font_import->family_urlname,
|
||||
'font_filename' => $font_import->font_filename,
|
||||
);
|
||||
|
||||
$font = new StdClass;
|
||||
$font->name = $font_import->family_name;
|
||||
$font->url = 'http://www.fontsquirrel.com/fonts/' . $font_import->family_urlname;
|
||||
$font->provider = 'fontsquirrel';
|
||||
$font->foundry = $font_import->foundry_name;
|
||||
$font->foundry_url = 'http://www.fontsquirrel.com/foundry/' . $font_import->foundry_urlname;
|
||||
$font->license = 'See Font Squirrel license page';
|
||||
$font->license_url = 'http://www.fontsquirrel.com/fonts/' . $font_import->family_urlname . '#eula';
|
||||
$font->tags = array($font_import->classification);
|
||||
$font->metadata = serialize($metadata);
|
||||
|
||||
fontyourface_save_font($font);
|
||||
|
||||
}
|
||||
} // foreach
|
||||
|
||||
if (count($families) > 0) {
|
||||
$batch = array(
|
||||
'operations' => array(array('fontsquirrel_batch_import', array($families))),
|
||||
'title' => t('@count font families contain multiple variants', array('@count' => count($families))),
|
||||
'progress_message' => t('Importing variants...'),
|
||||
);
|
||||
batch_set($batch);
|
||||
}
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error downloading font list from Font Squirrel.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
} // fontsquirrel_fontyourface_import
|
||||
|
||||
/**
|
||||
* Batch processing function - import font variants.
|
||||
*/
|
||||
function fontsquirrel_batch_import($families, &$context) {
|
||||
if (!isset($context['sandbox']['progress'])) {
|
||||
$context['sandbox']['progress'] = 0;
|
||||
$context['sandbox']['max'] = count($families);
|
||||
$context['sandbox']['families'] = $families;
|
||||
}
|
||||
|
||||
// Import variants of one family.
|
||||
$family = array_shift($context['sandbox']['families']);
|
||||
$variants_raw = drupal_http_request('http://www.fontsquirrel.com/api/familyinfo/' . $family);
|
||||
$variants = json_decode($variants_raw->data);
|
||||
foreach ($variants as $key => $variant) {
|
||||
$metadata = array(
|
||||
'id' => $variant->family_id,
|
||||
'path' => $variant->family_urlname,
|
||||
'font_filename' => $variant->filename,
|
||||
);
|
||||
$font = new StdClass;
|
||||
$font->name = $variant->family_name . ' ' . $variant->style_name;
|
||||
$font->url = 'http://www.fontsquirrel.com/fonts/' . $variant->family_urlname;
|
||||
// To make URL unique, add a fake anchor, except for the first variant.
|
||||
if ($key != 0) {
|
||||
$font->url .= '#' . drupal_strtolower($variant->fontface_name);
|
||||
}
|
||||
$font->css_family = $variant->fontface_name;
|
||||
$font->provider = 'fontsquirrel';
|
||||
$font->foundry = $variant->foundry_name;
|
||||
$font->foundry_url = 'http://www.fontsquirrel.com/foundry/' . $variant->foundry_urlname;
|
||||
$font->license = 'See Font Squirrel license page';
|
||||
$font->license_url = 'http://www.fontsquirrel.com/fonts/' . $variant->family_urlname . '#eula';
|
||||
$font->tags = array($variant->classification);
|
||||
$font->metadata = serialize($metadata);
|
||||
fontyourface_save_font($font);
|
||||
}
|
||||
|
||||
// Update progress indicator.
|
||||
$context['sandbox']['progress']++;
|
||||
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
|
||||
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,178 @@
|
||||
#fontyourface-apply-tabs ul {
|
||||
border: none;
|
||||
}
|
||||
|
||||
#fontyourface-ui-apply-by-font-form tbody tr td.css-selector div.form-type-textfield {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse ul.tabs {
|
||||
border-bottom: 1px solid #a6a7a2;
|
||||
font-size: 0.923em;
|
||||
margin: 0;
|
||||
padding: 0.769em 0 5px 0;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse ul.tabs li {
|
||||
display: inline;
|
||||
list-style: none;
|
||||
position: relative;
|
||||
top: 3px;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse ul.tabs li a {
|
||||
background: #a6a7a2;
|
||||
border-color: #a6a7a2;
|
||||
border-style: solid;
|
||||
border-radius: 8px 8px 0 0;
|
||||
border-width: 1px 1px 0 1px;
|
||||
color: #000;
|
||||
font-weight: bold;
|
||||
margin-right: 4px;
|
||||
padding: 6px 20px;
|
||||
text-decoration: none;
|
||||
-moz-border-radius: 8px 8px 0 0;
|
||||
-webkit-border-radius: 8px 8px 0 0;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse ul.tabs li a:hover {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse ul.tabs li a.active {
|
||||
background: #fff;
|
||||
border-color: #c9cAc4;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse ul.tabs li a.active:hover {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse ul.fonts-listing {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse li.font {
|
||||
position: relative;
|
||||
float: left;
|
||||
width: 172px;
|
||||
height: 152px;
|
||||
float: left;
|
||||
margin: 8px;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-header {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-header h4 {
|
||||
height: 40px;
|
||||
left: 20px;
|
||||
margin: 0 10px 10px 0;
|
||||
overflow: hidden;
|
||||
padding: 0 25px 0 0;
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse li:hover div.fontyourface-header h4 {
|
||||
background: #fff;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse li:hover div.fontyourface-header.enabled-yes h4 {
|
||||
background: #dfd;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-header a {
|
||||
background: transparent url(gear-select.png) no-repeat 2px 0;
|
||||
display: none;
|
||||
height: 18px;
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
top: 15px;
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse li:hover div.fontyourface-header a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-header a:hover {
|
||||
background-position-y: -18px;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-header a span {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-preview {
|
||||
-webkit-border-radius: 8px;
|
||||
-moz-border-radius: 8px;
|
||||
border-radius: 8px;
|
||||
|
||||
border: 1px solid #ccc;
|
||||
display: inline-block;
|
||||
height: 10px;
|
||||
margin: 0;
|
||||
padding: 70px 10px;
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-footer {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-footer a {
|
||||
-webkit-border-radius: 0 0 8px 8px;
|
||||
-moz-border-radius: 0 0 8px 8px;
|
||||
border-radius: 0 0 8px 8px;
|
||||
border-bottom: 1px solid #ccc;
|
||||
border-left: 1px solid #ccc;
|
||||
border-right: 1px solid #ccc;
|
||||
top: 121px;
|
||||
display: block;
|
||||
height: 20px;
|
||||
left: -10px;
|
||||
margin: 0 10px 10px 10px;
|
||||
padding: 5px 10px;
|
||||
position: absolute;
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-footer .fontyourface-indicator {
|
||||
background: url(indicator.gif);
|
||||
display: inline-block;
|
||||
float: right;
|
||||
height: 16px;
|
||||
position: relative;
|
||||
top: 2px;
|
||||
width: 16px;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.enabled-no {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-footer.enabled-no a {
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-footer.enabled-no a:active {
|
||||
background: #ddd;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.enabled-yes {
|
||||
background: #dfd;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-footer.enabled-yes a {
|
||||
background: #bdb;
|
||||
}
|
||||
|
||||
.view-fontyourface-browse div.fontyourface-footer.enabled-yes a:active {
|
||||
background: #aca;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 506 B |
Binary file not shown.
After Width: | Height: | Size: 673 B |
@@ -0,0 +1,28 @@
|
||||
name = @font-your-face UI
|
||||
description = Administrative interface for managing fonts.
|
||||
package = @font-your-face
|
||||
dependencies[] = fontyourface
|
||||
dependencies[] = views
|
||||
configure = admin/config/user-interface/fontyourface
|
||||
core = 7.x
|
||||
|
||||
files[] = views/fontyourface.views_default.inc
|
||||
files[] = views/views_handler_field_fontyourface_font.inc
|
||||
files[] = views/views_handler_field_fontyourface_foundry.inc
|
||||
files[] = views/views_handler_field_fontyourface_license.inc
|
||||
files[] = views/views_handler_field_fontyourface_provider.inc
|
||||
files[] = views/views_handler_field_fontyourface_tag_font_tid.inc
|
||||
files[] = views/views_handler_filter_tag_font_tid.inc
|
||||
files[] = views/views_handler_relationship_fontyourface_tag.inc
|
||||
files[] = views/views_handler_field_fontyourface_preview.inc
|
||||
files[] = views/views_handler_field_fontyourface_enable_disable.inc
|
||||
files[] = views/views_handler_field_fontyourface_enabled_yes_no.inc
|
||||
files[] = views/views_handler_filter_fontyourface_provider.inc
|
||||
files[] = views/views_handler_filter_fontyourface_foundry.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,79 @@
|
||||
var fontyourfaceSampleText = '';
|
||||
var fontyourfaceSampleMarkup = '';
|
||||
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.fontyourfaceAddForm = {
|
||||
|
||||
attach:function(context, settings) {
|
||||
|
||||
var input = $('#edit-css');
|
||||
var selector = input.val();
|
||||
|
||||
fontyourfaceSampleText = $('#edit-sample-text').val();
|
||||
fontyourfaceSampleMarkup = $('.fontyourface-view').html();
|
||||
|
||||
$('#edit-sample-text').keyup(function() {
|
||||
|
||||
var markup = fontyourfaceSampleMarkup;
|
||||
var updatedText = $('#edit-sample-text').val();
|
||||
|
||||
if (updatedText != fontyourfaceSampleText) {
|
||||
|
||||
markup = markup.split(fontyourfaceSampleText).join(updatedText);
|
||||
markup = markup.split(fontyourfaceEncodeURI(fontyourfaceSampleText)).join(fontyourfaceEncodeURI(updatedText));
|
||||
|
||||
} // if
|
||||
|
||||
$('.fontyourface-view').html(markup);
|
||||
|
||||
});
|
||||
|
||||
if (selector && selector.length > 0) {
|
||||
|
||||
var select = $('<select id="edit-css-select"><option value="">-- none --</option><option value="h1, h2, h3, h4, h5, h6">all headers (h1, h2, h3, h4, h5, h6)</option><option value="h1">h1</option><option value="h2">h2</option><option value="h3">h3</option><option value="p, div">standard text (p, div)</option><option value="body">everything (body)</option><option value="<none>">-- add selector in theme CSS --</option><option value="-- other --">other</option>')
|
||||
.change(fontyourfaceCssSelectChange)
|
||||
.insertBefore(input);
|
||||
|
||||
if (select.find('option[value="' + selector + '"]').length > 0) {
|
||||
|
||||
select.find('option[value=' + selector + ']').attr('selected', true);
|
||||
input.hide();
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
select.find('option[value="-- other --"]').attr('selected', true);
|
||||
input.show();
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
} // attach
|
||||
|
||||
} // Drupal.behaviors.fontyourfaceAddForm
|
||||
|
||||
function fontyourfaceCssSelectChange() {
|
||||
|
||||
var selector = $(this).val();
|
||||
|
||||
if (selector == '') {
|
||||
$('#edit-css').show();
|
||||
} // if
|
||||
else {
|
||||
$('#edit-css').val(selector);
|
||||
$('#edit-css').hide();
|
||||
} // else
|
||||
|
||||
} // fontyourfaceCssSelectChange
|
||||
|
||||
function fontyourfaceEncodeURI(text) {
|
||||
|
||||
return encodeURIComponent(text)
|
||||
.replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28')
|
||||
.replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
|
||||
|
||||
} // fontyourfaceEncodeURI
|
||||
|
||||
})(jQuery);
|
@@ -0,0 +1,69 @@
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.fontyourfaceBrowse = {
|
||||
|
||||
attach:function(context, settings) {
|
||||
|
||||
$('#fontyourface-apply-tabs').tabs();;
|
||||
|
||||
$('#fontyourface-apply-tabs .css-selector input').each(function(){
|
||||
|
||||
var input = $(this);
|
||||
var selector = input.val();
|
||||
|
||||
var select = $('<select><option value="">-- none --</option><option value="h1, h2, h3, h4, h5, h6">all headers (h1, h2, h3, h4, h5, h6)</option><option value="h1">h1</option><option value="h2">h2</option><option value="h3">h3</option><option value="p, div">standard text (p, div)</option><option value="body">everything (body)</option><option value="<none>">-- add selector in theme CSS --</option><option value="-- other --">other</option></select>')
|
||||
.change(fontyourfaceCssSelectChange)
|
||||
.insertBefore(input.parent());
|
||||
|
||||
if (select.find('option[value="' + selector + '"]').length > 0) {
|
||||
|
||||
select.find('option[value=' + selector + ']').attr('selected', true);
|
||||
input.hide();
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
select.find('option[value="-- other --"]').attr('selected', true);
|
||||
input.show();
|
||||
|
||||
} // else
|
||||
|
||||
});
|
||||
|
||||
} // attach
|
||||
|
||||
} // Drupal.behaviors.fontyourfaceAddForm
|
||||
|
||||
function fontyourfaceCssSelectChange() {
|
||||
|
||||
var select = $(this);
|
||||
var selector = select.val();
|
||||
var input = select.parent().find('input');
|
||||
var fontFamily = select.parent().attr('data-font-family');
|
||||
|
||||
if (selector == '-- other --') {
|
||||
|
||||
if (input.val() == '<none>') {
|
||||
input.val('');
|
||||
} // if
|
||||
|
||||
input.show();
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
input.val(selector);
|
||||
input.hide();
|
||||
select.parent().find('.font-family').remove();
|
||||
|
||||
if (selector == '<none>') {
|
||||
|
||||
select.parent().append('<div class="font-family">font-family: "' + fontFamily + '";</div>');
|
||||
|
||||
} // if
|
||||
|
||||
} // else
|
||||
|
||||
} // fontyourfaceCssSelectChange
|
||||
|
||||
})(jQuery);
|
@@ -0,0 +1,84 @@
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.fontyourfaceBrowse = {
|
||||
|
||||
attach:function(context, settings) {
|
||||
|
||||
$('.fontyourface-footer a.enable-link').click(fontyourfaceEnableClick);
|
||||
$('.fontyourface-footer a.disable-link').click(fontyourfaceDisableClick);
|
||||
|
||||
} // attach
|
||||
|
||||
} // Drupal.behaviors.fontyourfaceAddForm
|
||||
|
||||
function fontyourfaceEnableClick() {
|
||||
|
||||
var link = $(this);
|
||||
var fid = link.parent().attr('data-fid');
|
||||
var enableUrl = Drupal.settings.basePath + '?q=admin/appearance/fontyourface/ajax/enable/' + fid;
|
||||
|
||||
$('<span class="fontyourface-indicator"></span>').appendTo(this);
|
||||
|
||||
$.post(enableUrl, {fid: fid}, function(json) {
|
||||
|
||||
var font = link.parents('.font');
|
||||
|
||||
if (json.complete == '1') {
|
||||
|
||||
font.find('.enabled-no')
|
||||
.addClass('enabled-yes')
|
||||
.removeClass('enabled-no');
|
||||
link
|
||||
.text(Drupal.t('Disable'))
|
||||
.addClass('disable-link')
|
||||
.removeClass('enable-link')
|
||||
.unbind('click')
|
||||
.click(fontyourfaceDisableClick);
|
||||
|
||||
} // if
|
||||
|
||||
font.find('.fontyourface-indicator').remove();
|
||||
$('.view-header div').html(json.status);
|
||||
|
||||
}, 'json');
|
||||
|
||||
return false;
|
||||
|
||||
} // fontyourfaceEnableClick
|
||||
|
||||
function fontyourfaceDisableClick() {
|
||||
|
||||
var link = $(this);
|
||||
var fid = link.parent().attr('data-fid');
|
||||
var disableUrl = Drupal.settings.basePath + '?q=admin/appearance/fontyourface/ajax/disable/';
|
||||
|
||||
$('<span class="fontyourface-indicator"></span>').appendTo(this);
|
||||
|
||||
$.post(disableUrl, {fid: fid}, function(json) {
|
||||
|
||||
var font = link.parents('.font');
|
||||
|
||||
if (json.complete == '1') {
|
||||
|
||||
font.find('.enabled-yes')
|
||||
.addClass('enabled-no')
|
||||
.removeClass('enabled-yes');
|
||||
link
|
||||
.text(Drupal.t('Enable'))
|
||||
.addClass('enable-link')
|
||||
.removeClass('disable-link')
|
||||
.unbind('click')
|
||||
.click(fontyourfaceEnableClick);
|
||||
|
||||
} // if
|
||||
|
||||
font.find('.fontyourface-indicator').remove();
|
||||
$('.view-header div').html(json.status);
|
||||
|
||||
}, 'json');
|
||||
|
||||
return false;
|
||||
|
||||
} // fontyourfaceDisableClick
|
||||
|
||||
})(jQuery);
|
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Adds default views.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_default_views().
|
||||
*/
|
||||
function fontyourface_ui_views_default_views() {
|
||||
/*
|
||||
* View 'fontyourface_browse'
|
||||
*/
|
||||
$view = new view;
|
||||
$view->name = 'fontyourface_browse';
|
||||
$view->description = 'Browsing interface for fonts.';
|
||||
$view->tag = '@font-your-face';
|
||||
$view->base_table = 'fontyourface_font';
|
||||
$view->human_name = '@font-your-face Browse';
|
||||
$view->core = 0;
|
||||
$view->api_version = '3.0';
|
||||
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
||||
|
||||
/* Display: Defaults */
|
||||
$handler = $view->new_display('default', 'Defaults', 'default');
|
||||
$handler->display->display_options['title'] = 'Browse all fonts';
|
||||
$handler->display->display_options['use_ajax'] = TRUE;
|
||||
$handler->display->display_options['access']['type'] = 'perm';
|
||||
$handler->display->display_options['access']['perm'] = 'administer @font-your-face';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['distinct'] = TRUE;
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE;
|
||||
$handler->display->display_options['exposed_form']['options']['autosubmit'] = 1;
|
||||
$handler->display->display_options['exposed_form']['options']['autosubmit_hide'] = 0;
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '50';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['pager']['options']['id'] = '0';
|
||||
$handler->display->display_options['pager']['options']['expose']['items_per_page_options_all'] = 0;
|
||||
$handler->display->display_options['style_plugin'] = 'list';
|
||||
$handler->display->display_options['style_options']['row_class'] = 'font';
|
||||
$handler->display->display_options['style_options']['class'] = 'fonts-listing';
|
||||
$handler->display->display_options['style_options']['wrapper_class'] = '';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Header: Global: Text area */
|
||||
$handler->display->display_options['header']['area']['id'] = 'area';
|
||||
$handler->display->display_options['header']['area']['table'] = 'views';
|
||||
$handler->display->display_options['header']['area']['field'] = 'area';
|
||||
$handler->display->display_options['header']['area']['empty'] = TRUE;
|
||||
$handler->display->display_options['header']['area']['content'] = '0 fonts currently enabled.';
|
||||
$handler->display->display_options['header']['area']['format'] = 'filtered_html';
|
||||
$handler->display->display_options['header']['area']['tokenize'] = 0;
|
||||
/* Relationship: Font: Font Tag */
|
||||
$handler->display->display_options['relationships']['tid']['id'] = 'tid';
|
||||
$handler->display->display_options['relationships']['tid']['table'] = 'fontyourface_tag_font';
|
||||
$handler->display->display_options['relationships']['tid']['field'] = 'tid';
|
||||
$handler->display->display_options['relationships']['tid']['required'] = 0;
|
||||
/* Field: Font: Name */
|
||||
$handler->display->display_options['fields']['name_1']['id'] = 'name_1';
|
||||
$handler->display->display_options['fields']['name_1']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['name_1']['field'] = 'name';
|
||||
$handler->display->display_options['fields']['name_1']['label'] = '';
|
||||
$handler->display->display_options['fields']['name_1']['exclude'] = TRUE;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['alter_text'] = 1;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['text'] = '<span>Edit</span>';
|
||||
$handler->display->display_options['fields']['name_1']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['name_1']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['name_1']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['name_1']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['link_to_font'] = 'edit';
|
||||
$handler->display->display_options['fields']['name_1']['display_as'] = '0';
|
||||
/* Field: Font: Font ID */
|
||||
$handler->display->display_options['fields']['fid']['id'] = 'fid';
|
||||
$handler->display->display_options['fields']['fid']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['fid']['field'] = 'fid';
|
||||
$handler->display->display_options['fields']['fid']['label'] = '';
|
||||
$handler->display->display_options['fields']['fid']['exclude'] = TRUE;
|
||||
$handler->display->display_options['fields']['fid']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['fid']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['fid']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['fid']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['fid']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['fid']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['separator'] = '';
|
||||
$handler->display->display_options['fields']['fid']['format_plural'] = 0;
|
||||
/* Field: Font: Enabled Yes/No */
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['id'] = 'enabled_yes_no';
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['field'] = 'enabled_yes_no';
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['label'] = '';
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['exclude'] = TRUE;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['element_default_classes'] = 1;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['hide_alter_empty'] = 1;
|
||||
/* Field: Font: Name */
|
||||
$handler->display->display_options['fields']['name']['id'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['name']['field'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['label'] = '';
|
||||
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 1;
|
||||
$handler->display->display_options['fields']['name']['alter']['text'] = '<div class="fontyourface-header enabled-[enabled_yes_no]"><h4>[name]</h4> [name_1]</div>';
|
||||
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['name']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['name']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['name']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['name']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name']['link_to_font'] = '0';
|
||||
$handler->display->display_options['fields']['name']['display_as'] = '0';
|
||||
/* Field: Font: Enable/Disable */
|
||||
$handler->display->display_options['fields']['enable_disable_link']['id'] = 'enable_disable_link';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['field'] = 'enable_disable_link';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['label'] = '';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['alter_text'] = 1;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['text'] = '<div class="fontyourface-footer enabled-[enabled_yes_no]" data-fid="[fid]">[enable_disable_link]</div>';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['hide_alter_empty'] = 0;
|
||||
/* Field: Font: Preview */
|
||||
$handler->display->display_options['fields']['preview']['id'] = 'preview';
|
||||
$handler->display->display_options['fields']['preview']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['preview']['field'] = 'preview';
|
||||
$handler->display->display_options['fields']['preview']['label'] = '';
|
||||
$handler->display->display_options['fields']['preview']['alter']['alter_text'] = 1;
|
||||
$handler->display->display_options['fields']['preview']['alter']['text'] = '<div class="fontyourface-preview enabled-[enabled_yes_no]">[preview]</div>';
|
||||
$handler->display->display_options['fields']['preview']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['preview']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['preview']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['preview']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['preview']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['preview']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['hide_alter_empty'] = 0;
|
||||
/* Sort criterion: Font: Name */
|
||||
$handler->display->display_options['sorts']['name']['id'] = 'name';
|
||||
$handler->display->display_options['sorts']['name']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['sorts']['name']['field'] = 'name';
|
||||
/* Contextual filter: Font: Provider */
|
||||
$handler->display->display_options['arguments']['provider']['id'] = 'provider';
|
||||
$handler->display->display_options['arguments']['provider']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['arguments']['provider']['field'] = 'provider';
|
||||
$handler->display->display_options['arguments']['provider']['title_enable'] = 1;
|
||||
$handler->display->display_options['arguments']['provider']['title'] = 'Browse all fonts: %1';
|
||||
$handler->display->display_options['arguments']['provider']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['provider']['default_argument_skip_url'] = 0;
|
||||
$handler->display->display_options['arguments']['provider']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['provider']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['provider']['summary_options']['items_per_page'] = '25';
|
||||
$handler->display->display_options['arguments']['provider']['glossary'] = 0;
|
||||
$handler->display->display_options['arguments']['provider']['limit'] = '0';
|
||||
$handler->display->display_options['arguments']['provider']['transform_dash'] = 0;
|
||||
$handler->display->display_options['arguments']['provider']['break_phrase'] = 0;
|
||||
/* Filter criterion: Font: Name */
|
||||
$handler->display->display_options['filters']['name']['id'] = 'name';
|
||||
$handler->display->display_options['filters']['name']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['name']['field'] = 'name';
|
||||
$handler->display->display_options['filters']['name']['operator'] = 'contains';
|
||||
$handler->display->display_options['filters']['name']['group'] = 0;
|
||||
$handler->display->display_options['filters']['name']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['name']['expose']['operator_id'] = 'name_op';
|
||||
$handler->display->display_options['filters']['name']['expose']['label'] = 'Name';
|
||||
$handler->display->display_options['filters']['name']['expose']['operator'] = 'name_op';
|
||||
$handler->display->display_options['filters']['name']['expose']['identifier'] = 'name';
|
||||
/* Filter criterion: Tag */
|
||||
$handler->display->display_options['filters']['tid_3']['id'] = 'tid_3';
|
||||
$handler->display->display_options['filters']['tid_3']['table'] = 'fontyourface_tag';
|
||||
$handler->display->display_options['filters']['tid_3']['field'] = 'tid';
|
||||
$handler->display->display_options['filters']['tid_3']['relationship'] = 'tid';
|
||||
$handler->display->display_options['filters']['tid_3']['ui_name'] = 'Tag';
|
||||
$handler->display->display_options['filters']['tid_3']['group'] = 0;
|
||||
$handler->display->display_options['filters']['tid_3']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['operator_id'] = 'tid_3_op';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['label'] = 'Tag';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['operator'] = 'tid_3_op';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['identifier'] = 'tag_id';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['reduce'] = 0;
|
||||
$handler->display->display_options['filters']['tid_3']['reduce_duplicates'] = 0;
|
||||
$handler->display->display_options['filters']['tid_3']['type'] = 'select';
|
||||
$handler->display->display_options['filters']['tid_3']['tag_type'] = 'tag';
|
||||
/* Filter criterion: Font: Foundry */
|
||||
$handler->display->display_options['filters']['foundry']['id'] = 'foundry';
|
||||
$handler->display->display_options['filters']['foundry']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['foundry']['field'] = 'foundry';
|
||||
$handler->display->display_options['filters']['foundry']['group'] = 0;
|
||||
$handler->display->display_options['filters']['foundry']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['foundry']['expose']['operator_id'] = 'foundry_op';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['label'] = 'Foundry';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['operator'] = 'foundry_op';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['identifier'] = 'foundry';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['reduce'] = 0;
|
||||
/* Filter criterion: Font: License */
|
||||
$handler->display->display_options['filters']['license']['id'] = 'license';
|
||||
$handler->display->display_options['filters']['license']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['license']['field'] = 'license';
|
||||
$handler->display->display_options['filters']['license']['operator'] = 'contains';
|
||||
$handler->display->display_options['filters']['license']['group'] = 0;
|
||||
$handler->display->display_options['filters']['license']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['license']['expose']['operator_id'] = 'license_op';
|
||||
$handler->display->display_options['filters']['license']['expose']['label'] = 'License';
|
||||
$handler->display->display_options['filters']['license']['expose']['operator'] = 'license_op';
|
||||
$handler->display->display_options['filters']['license']['expose']['identifier'] = 'license';
|
||||
$handler->display->display_options['filters']['license']['expose']['required'] = 0;
|
||||
$handler->display->display_options['filters']['license']['expose']['multiple'] = FALSE;
|
||||
|
||||
/* Display: Browse */
|
||||
$handler = $view->new_display('page', 'Browse', 'page_1');
|
||||
$handler->display->display_options['path'] = 'admin/appearance/fontyourface/browse';
|
||||
$handler->display->display_options['menu']['type'] = 'tab';
|
||||
$handler->display->display_options['menu']['title'] = 'Browse all fonts';
|
||||
$handler->display->display_options['menu']['weight'] = '0';
|
||||
$translatables['fontyourface_browse'] = array(
|
||||
t('Defaults'),
|
||||
t('Browse all fonts'),
|
||||
t('more'),
|
||||
t('Apply'),
|
||||
t('Reset'),
|
||||
t('Sort by'),
|
||||
t('Asc'),
|
||||
t('Desc'),
|
||||
t('Items per page'),
|
||||
t('- All -'),
|
||||
t('Offset'),
|
||||
t('0 fonts currently enabled.'),
|
||||
t('Font Tag'),
|
||||
t('<span>Edit</span>'),
|
||||
t('.'),
|
||||
t('<div class="fontyourface-header enabled-[enabled_yes_no]"><h4>[name]</h4> [name_1]</div>'),
|
||||
t('<div class="fontyourface-footer enabled-[enabled_yes_no]" data-fid="[fid]">[enable_disable_link]</div>'),
|
||||
t('<div class="fontyourface-preview enabled-[enabled_yes_no]">[preview]</div>'),
|
||||
t('All'),
|
||||
t('Browse all fonts: %1'),
|
||||
t('Name'),
|
||||
t('Tag'),
|
||||
t('Foundry'),
|
||||
t('License'),
|
||||
t('Browse'),
|
||||
);
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
return $views;
|
||||
|
||||
} // fontyourface_ui_views_default_views
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present font enable/disable link.
|
||||
*/
|
||||
class views_handler_field_fontyourface_enable_disable extends views_handler_field {
|
||||
|
||||
function construct() {
|
||||
|
||||
parent::construct();
|
||||
$this->additional_fields['enabled'] = 'enabled';
|
||||
$this->additional_fields['fid'] = 'fid';
|
||||
|
||||
} // construct
|
||||
|
||||
function query() {
|
||||
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
|
||||
} // query
|
||||
|
||||
function render($values) {
|
||||
|
||||
$enabled = $this->get_value($values, 'enabled');
|
||||
$fid = $this->get_value($values, 'fid');
|
||||
$destination = drupal_get_destination();
|
||||
|
||||
if ($enabled) {
|
||||
|
||||
return l(t('Disable'), 'admin/appearance/fontyourface/disable/' . $fid . '?' . drupal_http_build_query($destination), array('attributes' => array('class' => 'disable-link')));
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
return l(t('Enable'), 'admin/appearance/fontyourface/enable/' . $fid . '?' . drupal_http_build_query($destination), array('attributes' => array('class' => 'enable-link')));
|
||||
|
||||
} // else
|
||||
|
||||
} // render
|
||||
|
||||
} // views_handler_field_fontyourface_preview
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to present font enable/disable link.
|
||||
*/
|
||||
class views_handler_field_fontyourface_enabled_yes_no extends views_handler_field {
|
||||
|
||||
function construct() {
|
||||
|
||||
parent::construct();
|
||||
$this->additional_fields['enabled'] = 'enabled';
|
||||
|
||||
} // construct
|
||||
|
||||
function query() {
|
||||
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
|
||||
} // query
|
||||
|
||||
function render($values) {
|
||||
|
||||
$enabled = $this->get_value($values, 'enabled');
|
||||
|
||||
// This intentionall not translated, so it can be used in class names.
|
||||
|
||||
if ($enabled) {
|
||||
|
||||
return 'yes';
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
return 'no';
|
||||
|
||||
} // else
|
||||
|
||||
} // render
|
||||
|
||||
} // views_handler_field_fontyourface_enabled_yes_no
|
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to a font.
|
||||
*/
|
||||
class views_handler_field_fontyourface_font extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Override init function to provide generic option to link to font.
|
||||
*/
|
||||
function init(&$view, &$data) {
|
||||
|
||||
parent::init($view, $data);
|
||||
|
||||
if (!empty($this->options['link_to_font'])) {
|
||||
$this->additional_fields['fid'] = 'fid';
|
||||
} // if
|
||||
|
||||
} // init
|
||||
|
||||
function option_definition() {
|
||||
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_font'] = array('default' => 0);
|
||||
$options['display_as'] = array('default' => 0);
|
||||
|
||||
return $options;
|
||||
|
||||
} // option_definition
|
||||
|
||||
/**
|
||||
* Provide link to font option
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['link_to_font'] = array(
|
||||
'#title' => t('Link this field'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
0 => t('No link'),
|
||||
'edit' => t('To the font edit page'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_font'],
|
||||
);
|
||||
|
||||
$form['display_as'] = array(
|
||||
'#title' => t('Display as'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
0 => t('Plain text'),
|
||||
'preview' => t('Font preview'),
|
||||
),
|
||||
'#default_value' => $this->options['display_as'],
|
||||
);
|
||||
|
||||
} // options_form
|
||||
|
||||
function render($values) {
|
||||
|
||||
if ($this->options['link_to_font'] == 'edit') {
|
||||
|
||||
$destination = drupal_get_destination();
|
||||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = 'admin/appearance/fontyourface/edit/' . $values->{$this->aliases['fid']} . '?' . drupal_http_build_query($destination);
|
||||
|
||||
} // if
|
||||
|
||||
if ($this->options['display_as'] == 'preview') {
|
||||
|
||||
$font = fontyourface_get_font($values->fid);
|
||||
return fontyourface_preview($font, $values->{$this->field_alias}, 16);
|
||||
|
||||
} // if
|
||||
|
||||
return check_plain($values->{$this->field_alias});
|
||||
|
||||
} // render
|
||||
|
||||
} // views_handler_field_fontyourface_font
|
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to a foundry.
|
||||
*/
|
||||
class views_handler_field_fontyourface_foundry extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Override init function to provide generic option to link to foundry.
|
||||
*/
|
||||
function init(&$view, &$data) {
|
||||
|
||||
parent::init($view, $data);
|
||||
|
||||
if (!empty($this->options['link_to_foundry'])) {
|
||||
$this->additional_fields['foundry_url'] = 'foundry_url';
|
||||
} // if
|
||||
|
||||
} // init
|
||||
|
||||
function option_definition() {
|
||||
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_foundry'] = array('default' => 0);
|
||||
|
||||
return $options;
|
||||
|
||||
} // option_definition
|
||||
|
||||
/**
|
||||
* Provide link to font option
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['link_to_foundry'] = array(
|
||||
'#title' => t('Link this field'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
0 => t('No link'),
|
||||
'foundry_url' => t('To the foundry URL (if available)'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_foundry'],
|
||||
);
|
||||
|
||||
} // options_form
|
||||
|
||||
function render($values) {
|
||||
|
||||
if ($this->options['link_to_foundry'] == 'foundry_url') {
|
||||
|
||||
$foundry_url = $values->{$this->aliases['foundry_url']};
|
||||
|
||||
if ($foundry_url != '') {
|
||||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = $foundry_url;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
$this->options['alter']['make_link'] = FALSE;
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
return check_plain($values->{$this->field_alias});
|
||||
|
||||
} // render
|
||||
|
||||
} // views_handler_field_fontyourface_foundry
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to a license.
|
||||
*/
|
||||
class views_handler_field_fontyourface_license extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Override init function to provide generic option to link to license.
|
||||
*/
|
||||
function init(&$view, &$data) {
|
||||
|
||||
parent::init($view, $data);
|
||||
|
||||
if (!empty($this->options['link_to_license'])) {
|
||||
$this->additional_fields['license_url'] = 'license_url';
|
||||
} // if
|
||||
|
||||
} // init
|
||||
|
||||
function option_definition() {
|
||||
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_license'] = array('default' => 0);
|
||||
|
||||
return $options;
|
||||
|
||||
} // option_definition
|
||||
|
||||
/**
|
||||
* Provide link to license option
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['link_to_license'] = array(
|
||||
'#title' => t('Link this field'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
0 => t('No link'),
|
||||
'license_url' => t('To the license URL (if available)'),
|
||||
),
|
||||
'#default_value' => $this->options['link_to_license'],
|
||||
);
|
||||
|
||||
} // options_form
|
||||
|
||||
function render($values) {
|
||||
|
||||
if ($this->options['link_to_license'] == 'license_url') {
|
||||
|
||||
$license_url = $values->{$this->aliases['license_url']};
|
||||
|
||||
if ($license_url != '') {
|
||||
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = $license_url;
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
return check_plain($values->{$this->field_alias});
|
||||
|
||||
} // render
|
||||
|
||||
} // views_handler_field_fontyourface_license
|
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Field handler to present font preview.
|
||||
*/
|
||||
class views_handler_field_fontyourface_preview extends views_handler_field {
|
||||
|
||||
function construct() {
|
||||
|
||||
parent::construct();
|
||||
$this->additional_fields['fid'] = 'fid';
|
||||
|
||||
} // construct
|
||||
|
||||
function query() {
|
||||
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
|
||||
} // query
|
||||
|
||||
function render($values) {
|
||||
|
||||
$fid = $this->get_value($values, 'fid');
|
||||
|
||||
$font = fontyourface_get_font($fid);
|
||||
return fontyourface_preview($font, fontyourface_short_preview_text($font), 40);
|
||||
|
||||
} // render
|
||||
|
||||
} // views_handler_field_fontyourface_preview
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to a font.
|
||||
*/
|
||||
class views_handler_field_fontyourface_provider extends views_handler_field {
|
||||
|
||||
function render($values) {
|
||||
|
||||
$info_function = $values->{$this->field_alias} . '_fontyourface_info';
|
||||
|
||||
if (function_exists($info_function)) {
|
||||
|
||||
$provider = $info_function();
|
||||
return check_plain($provider['name']);
|
||||
|
||||
} // if
|
||||
|
||||
return $values->{$this->field_alias};
|
||||
|
||||
} // render
|
||||
|
||||
} // views_handler_field_fontyourface_provider
|
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler for tags.
|
||||
* Largely copied from views_handler_field_term_node_tid.inc
|
||||
*/
|
||||
class views_handler_field_fontyourface_tag_font_tid extends views_handler_field_prerender_list {
|
||||
|
||||
function init(&$view, &$options) {
|
||||
|
||||
parent::init($view, $options);
|
||||
$this->additional_fields['fid'] = array('table' => 'fontyourface_font', 'field' => 'fid');
|
||||
|
||||
} // init
|
||||
|
||||
function option_definition() {
|
||||
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['link_to_tag'] = array('default' => TRUE);
|
||||
|
||||
return $options;
|
||||
|
||||
} // option_definition
|
||||
|
||||
/**
|
||||
* Provide "link to term" option.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['link_to_tag'] = array(
|
||||
'#title' => t('Link this field to its tag page'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['link_to_tag']),
|
||||
);
|
||||
|
||||
} // options_form
|
||||
|
||||
/**
|
||||
* Add this term to the query
|
||||
*/
|
||||
function query() {
|
||||
|
||||
$this->add_additional_fields();
|
||||
|
||||
} // query
|
||||
|
||||
function pre_render(&$values) {
|
||||
|
||||
$this->field_alias = $this->aliases['fid'];
|
||||
$fids = array();
|
||||
|
||||
foreach ($values as $result) {
|
||||
if (!empty($result->{$this->aliases['fid']})) {
|
||||
$fids[] = $result->{$this->aliases['fid']};
|
||||
} // if
|
||||
} // foreach
|
||||
|
||||
if ($fids) {
|
||||
|
||||
$query = db_select('fontyourface_tag', 't');
|
||||
$tag_font_alias = $query->join('fontyourface_tag_font', 'tf', 't.tid = tf.tid');
|
||||
$query
|
||||
->condition($tag_font_alias . '.fid', $fids, 'IN')
|
||||
->fields('t')
|
||||
->orderBy('t.name');
|
||||
$font_fid_field = $query->addField($tag_font_alias, 'fid', 'font_fid');
|
||||
|
||||
$result = $query->execute();
|
||||
|
||||
foreach ($result as $tag) {
|
||||
|
||||
$this->items[$tag->font_fid][$tag->tid]['name'] = check_plain($tag->name);
|
||||
$this->items[$tag->font_fid][$tag->tid]['tid'] = $tag->tid;
|
||||
|
||||
if (isset($tag->fid)) {
|
||||
$this->items[$tag->font_fid][$tag->tid]['fid'] = $tag->fid;
|
||||
} // if
|
||||
|
||||
if (!empty($this->options['link_to_tag'])) {
|
||||
|
||||
$this->items[$tag->font_fid][$tag->tid]['make_link'] = TRUE;
|
||||
$this->items[$tag->font_fid][$tag->tid]['path'] = 'admin/appearance/fontyourface/browse?tid[]=' . $tag->tid;
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
|
||||
} // pre_render
|
||||
|
||||
function render_item($count, $item) {
|
||||
|
||||
return $item['name'];
|
||||
|
||||
} // render_item
|
||||
|
||||
} // views_handler_field_fontyourface_tag_font_tid
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filters by provider.
|
||||
*/
|
||||
class views_handler_filter_fontyourface_foundry extends views_handler_filter_in_operator {
|
||||
|
||||
function get_value_options() {
|
||||
|
||||
if (!isset($this->value_options)) {
|
||||
|
||||
$this->value_title = t('Provider');
|
||||
$options = array();
|
||||
|
||||
$foundries = db_select('fontyourface_font', 'f')
|
||||
->fields('f', array('foundry'))
|
||||
->distinct()
|
||||
->execute();
|
||||
|
||||
foreach ($foundries as $foundry) {
|
||||
$options[$foundry->foundry] = $foundry->foundry;
|
||||
} // foreach
|
||||
|
||||
asort($options);
|
||||
$this->value_options = $options;
|
||||
|
||||
} // if
|
||||
|
||||
} // get_value_options
|
||||
|
||||
} // views_handler_filter_fontyourface_foundry
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filters by provider.
|
||||
*/
|
||||
|
||||
class views_handler_filter_fontyourface_provider extends views_handler_filter_in_operator {
|
||||
|
||||
function get_value_options() {
|
||||
|
||||
if (!isset($this->value_options)) {
|
||||
|
||||
$this->value_title = t('Provider');
|
||||
$options = array();
|
||||
|
||||
foreach (module_implements('fontyourface_info') as $module) {
|
||||
|
||||
$info_function = $module . '_fontyourface_info';
|
||||
$provider = $info_function();
|
||||
$options[$module] = $provider['name'];
|
||||
|
||||
} // foreach
|
||||
|
||||
asort($options);
|
||||
$this->value_options = $options;
|
||||
|
||||
} // if
|
||||
|
||||
} // get_value_options
|
||||
|
||||
} // views_handler_filter_fontyourface_provider
|
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filter by tag id.
|
||||
* Largely copied from views_handler_filter_term_node_tid.inc
|
||||
*/
|
||||
class views_handler_filter_tag_font_tid extends views_handler_filter_many_to_one {
|
||||
|
||||
function has_extra_options() {
|
||||
return TRUE;
|
||||
} // has_extra_options
|
||||
|
||||
function get_value_options() { }
|
||||
|
||||
function option_definition() {
|
||||
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['type'] = array('default' => 'textfield');
|
||||
$options['tag_type'] = array('default' => '*');
|
||||
|
||||
return $options;
|
||||
|
||||
} // option_definition
|
||||
|
||||
function extra_options_form(&$form, &$form_state) {
|
||||
|
||||
$form['type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Selection type'),
|
||||
'#options' => array('select' => t('Dropdown'), 'textfield' => t('Autocomplete')),
|
||||
'#default_value' => $this->options['type'],
|
||||
);
|
||||
|
||||
$type_options = array(
|
||||
'*' => '-- Any --'
|
||||
);
|
||||
$type_results = db_query('SELECT DISTINCT type FROM {fontyourface_tag}');
|
||||
|
||||
foreach ($type_results as $type_result) {
|
||||
$type_options[$type_result->type] = $type_result->type;
|
||||
} // foreach
|
||||
|
||||
$form['tag_type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Tag Type'),
|
||||
'#options' => $type_options,
|
||||
'#description' => t('Limit which type of tags to show options.'),
|
||||
'#default_value' => $this->options['tag_type'],
|
||||
);
|
||||
|
||||
} // extra_options_form
|
||||
|
||||
function value_form(&$form, &$form_state) {
|
||||
|
||||
if ($this->options['type'] == 'textfield') {
|
||||
|
||||
$default = '';
|
||||
|
||||
if ($this->value) {
|
||||
|
||||
$result = db_select('fontyourface_tag', 't')
|
||||
->condition('t.tid', $this->value, 'IN')
|
||||
->execute();
|
||||
|
||||
foreach ($result as $tag) {
|
||||
|
||||
if ($default) {
|
||||
$default .= ', ';
|
||||
} // if
|
||||
|
||||
$default .= $tag->name;
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
|
||||
$form['value'] = array(
|
||||
'#title' => t('Select tags'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $default,
|
||||
);
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
$options = array();
|
||||
|
||||
$query = db_select('fontyourface_tag', 't');
|
||||
$query
|
||||
->fields('t')
|
||||
->orderBy('t.name');
|
||||
|
||||
if (isset($this->options['tag_type']) && $this->options['tag_type'] != '*') {
|
||||
$query->condition('t.type', $this->options['tag_type']);
|
||||
} // if
|
||||
|
||||
$result = $query->execute();
|
||||
|
||||
while ($tag = $result->fetchObject()) {
|
||||
$options[$tag->tid] = $tag->name;
|
||||
} // while
|
||||
|
||||
$default_value = (array) $this->value;
|
||||
|
||||
if (!empty($form_state['exposed'])) {
|
||||
|
||||
$identifier = $this->options['expose']['identifier'];
|
||||
|
||||
if (!empty($this->options['expose']['reduce'])) {
|
||||
|
||||
$options = $this->reduce_value_options($options);
|
||||
|
||||
if (empty($this->options['expose']['single']) && !empty($this->options['expose']['optional'])) {
|
||||
$default_value = array();
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
if (!empty($this->options['expose']['single'])) {
|
||||
|
||||
if (!empty($this->options['expose']['optional']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) {
|
||||
$default_value = 'All';
|
||||
} // if
|
||||
elseif (empty($default_value)) {
|
||||
$keys = array_keys($options);
|
||||
$default_value = array_shift($keys);
|
||||
} // elseif
|
||||
else {
|
||||
$copy = $default_value;
|
||||
$default_value = array_shift($copy);
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
$form['value'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Select tags'),
|
||||
'#multiple' => TRUE,
|
||||
'#options' => $options,
|
||||
'#size' => min(9, count($options)),
|
||||
'#default_value' => $default_value,
|
||||
);
|
||||
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
|
||||
$form_state['input'][$identifier] = $default_value;
|
||||
} // if
|
||||
|
||||
} // else
|
||||
|
||||
if (empty($form_state['exposed'])) {
|
||||
$this->helper->options_form($form, $form_state);
|
||||
} // if
|
||||
|
||||
} // value_form
|
||||
|
||||
function value_validate($form, &$form_state) {
|
||||
|
||||
if ($this->options['type'] != 'textfield') {
|
||||
return;
|
||||
} // if
|
||||
|
||||
$values = drupal_explode_tags($form_state['values']['options']['value']);
|
||||
$tids = $this->validate_tag_strings($form['value'], $values);
|
||||
|
||||
if ($tids) {
|
||||
$form_state['values']['options']['value'] = $tids;
|
||||
} // if
|
||||
|
||||
} // value_validate
|
||||
|
||||
function accept_exposed_input($input) {
|
||||
|
||||
if (empty($this->options['exposed'])) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// If it's optional and there's no value don't bother filtering.
|
||||
if (isset($this->options['expose']['optional']) && $this->options['expose']['optional'] && empty($this->validated_exposed_input)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$rc = parent::accept_exposed_input($input);
|
||||
|
||||
if ($rc) {
|
||||
|
||||
// If we have previously validated input, override.
|
||||
if (isset($this->validated_exposed_input)) {
|
||||
$this->value = $this->validated_exposed_input;
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
return $rc;
|
||||
|
||||
} // value_validate
|
||||
|
||||
function exposed_validate(&$form, &$form_state) {
|
||||
|
||||
if (empty($this->options['exposed'])) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
$identifier = $this->options['expose']['identifier'];
|
||||
|
||||
if ($this->options['type'] != 'textfield') {
|
||||
|
||||
if ($form_state['values'][$identifier] != 'All') {
|
||||
$this->validated_exposed_input = (array) $form_state['values'][$identifier];
|
||||
} // if
|
||||
|
||||
return;
|
||||
|
||||
} // if
|
||||
|
||||
if (empty($this->options['expose']['identifier'])) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
$values = drupal_explode_tags($form_state['values'][$identifier]);
|
||||
|
||||
$tids = $this->validate_tag_strings($form[$identifier], $values);
|
||||
|
||||
if ($tids) {
|
||||
$this->validated_exposed_input = $tids;
|
||||
} // if
|
||||
|
||||
} // exposed_validate
|
||||
|
||||
/**
|
||||
* Validate the user string. Since this can come from either the form
|
||||
* or the exposed filter, this is abstracted out a bit so it can
|
||||
* handle the multiple input sources.
|
||||
*/
|
||||
function validate_tag_strings(&$form, $values) {
|
||||
|
||||
if (empty($values)) {
|
||||
return array();
|
||||
} // if
|
||||
|
||||
$tids = array();
|
||||
$args = array();
|
||||
$results = array();
|
||||
|
||||
foreach ($values as $value) {
|
||||
$missing[strtolower($value)] = TRUE;
|
||||
$args[] = $value;
|
||||
} // foreach
|
||||
|
||||
if (!$args) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
$result = db_select('fontyourface_tag', 't')
|
||||
->condition('t.name', $args, 'IN')
|
||||
->execute();
|
||||
|
||||
foreach ($result as $tag) {
|
||||
unset($missing[strtolower($tag->name)]);
|
||||
$tids[] = $tag->tid;
|
||||
} // foreach
|
||||
|
||||
if ($missing) {
|
||||
form_error($form, format_plural(count($missing), 'Unable to find tag: @tags', 'Unable to find tags: @tags', array('@tags' => implode(', ', array_keys($missing)))));
|
||||
} // if
|
||||
|
||||
return $tids;
|
||||
|
||||
} // validate_tag_strings
|
||||
|
||||
function value_submit($form, &$form_state) { }
|
||||
|
||||
function expose_form_right(&$form, &$form_state) {
|
||||
|
||||
parent::expose_form_right($form, $form_state);
|
||||
|
||||
if ($this->options['type'] != 'select') {
|
||||
unset($form['expose']['reduce']);
|
||||
} // if
|
||||
|
||||
} // expose_form_right
|
||||
|
||||
function admin_summary() {
|
||||
|
||||
$this->value_options = array();
|
||||
|
||||
if ($this->value) {
|
||||
|
||||
$result = db_select('fontyourface_tag', 't')
|
||||
->condition('t.tid', $this->value, 'IN')
|
||||
->execute();
|
||||
|
||||
foreach ($result as $tag) {
|
||||
$this->value_options[$tag->tid] = $tag->name;
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
|
||||
return parent::admin_summary();
|
||||
|
||||
} // admin_summary
|
||||
|
||||
} // views_handler_filter_tag_font_tid
|
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views handler.
|
||||
*/
|
||||
|
||||
class views_handler_relationship_fontyourface_tag extends views_handler_relationship {
|
||||
|
||||
/**
|
||||
* Called to implement a relationship in a query.
|
||||
*/
|
||||
function query() {
|
||||
|
||||
$this->ensure_my_table();
|
||||
|
||||
$def = $this->definition;
|
||||
$def['table'] = 'fontyourface_tag';
|
||||
|
||||
if (!empty($this->options['required'])) {
|
||||
|
||||
$tag_font = $this->query->add_table('fontyourface_tag_font', $this->relationship);
|
||||
$def['left_table'] = $tag_font;
|
||||
$def['left_field'] = 'tid';
|
||||
$def['field'] = 'tid';
|
||||
|
||||
if (!empty($this->options['required'])) {
|
||||
$def['type'] = 'INNER';
|
||||
} // if
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
// If the join is optional, join a subselect that will emulate fontyourface_tag_font table instead.
|
||||
$def['left_table'] = $this->table_alias;
|
||||
$def['left_field'] = 'fid';
|
||||
$def['field'] = 'font';
|
||||
$def['table formula'] = "(
|
||||
SELECT t.*, tf.fid AS font
|
||||
FROM {fontyourface_tag} t
|
||||
INNER JOIN {fontyourface_tag_font} tf
|
||||
ON t.tid = tf.tid
|
||||
)";
|
||||
|
||||
} // else
|
||||
|
||||
$join = new views_join();
|
||||
|
||||
$join->definition = $def;
|
||||
$join->construct();
|
||||
$join->adjusted = TRUE;
|
||||
|
||||
// use a short alias for this:
|
||||
$alias = $def['table'] . '_' . $this->table;
|
||||
$this->alias = $this->query->add_relationship($alias, $join, 'fontyourface_tag', $this->relationship);
|
||||
|
||||
} // query
|
||||
|
||||
} // views_handler_relationship_fontyourface_tag_font
|
@@ -0,0 +1,16 @@
|
||||
; $Id$
|
||||
name = WYSIWYG for @font-your-face
|
||||
description = Adds list of enabled fonts to WYSIWYG.
|
||||
dependencies[] = fontyourface
|
||||
dependencies[] = wysiwyg
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
|
||||
files[] = fontyourface_wysiwyg.module
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function fontyourface_wysiwyg_uninstall() {
|
||||
|
||||
variable_del('fontyourface_wysiwyg_css_md5');
|
||||
|
||||
} // fontyourface_wysiwyg_uninstall
|
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* Implements template_preprocess_page().
|
||||
*/
|
||||
function fontyourface_wysiwyg_preprocess_page(&$vars) {
|
||||
|
||||
$fonts = fontyourface_get_fonts();
|
||||
|
||||
$css = fontyourface_wysiwyg_generate_css($fonts);
|
||||
$css_md5 = md5($css);
|
||||
|
||||
if ($css_md5 != variable_get('fontyourface_wysiwyg_css_md5', '')) {
|
||||
|
||||
fontyourface_wysiwyg_rewrite_css($css);
|
||||
variable_set('fontyourface_wysiwyg_css_md5', $css_md5);
|
||||
|
||||
} // if
|
||||
|
||||
if ($css != '') {
|
||||
fontyourface_add_css_in_preprocess($vars, 'fontyourface/wysiwyg.css');
|
||||
} // if
|
||||
|
||||
} // fontyourface_wysiwyg_preprocess_page
|
||||
|
||||
/**
|
||||
* Generates CSS.
|
||||
*/
|
||||
function fontyourface_wysiwyg_generate_css($fonts = FALSE) {
|
||||
|
||||
// Get font list.
|
||||
|
||||
if (!$fonts) {
|
||||
$fonts = fontyourface_get_fonts();
|
||||
} // if
|
||||
|
||||
// Generate CSS.
|
||||
|
||||
$css = '';
|
||||
|
||||
foreach ($fonts as $font) {
|
||||
|
||||
$font_css = fontyourface_font_css($font);
|
||||
|
||||
if ($font_css != '') {
|
||||
$css .= '.fontyourface-' . $font->fid . ' { ' . $font_css . ' }' . "\n";
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
return $css;
|
||||
|
||||
} // fontyourface_wysiwyg_generate_css
|
||||
|
||||
/**
|
||||
* Re-writes wysiwyg.css file.
|
||||
*/
|
||||
function fontyourface_wysiwyg_rewrite_css($css) {
|
||||
|
||||
// Write CSS.
|
||||
|
||||
$destination = file_stream_wrapper_uri_normalize('public://fontyourface/wysiwyg.css');
|
||||
$destination_directory = dirname($destination);
|
||||
|
||||
if (file_prepare_directory($destination_directory, FILE_CREATE_DIRECTORY)) {
|
||||
file_unmanaged_save_data($css, $destination, FILE_EXISTS_REPLACE);
|
||||
} // if
|
||||
|
||||
} // fontyourface_wysiwyg_rewrite_css
|
||||
|
||||
/**
|
||||
* Implements hook_wysiwyg_include_directory().
|
||||
*/
|
||||
function fontyourface_wysiwyg_wysiwyg_include_directory($type) {
|
||||
|
||||
if ($type == 'plugins') {
|
||||
return 'plugins';
|
||||
} // if
|
||||
|
||||
} // fontyourface_wysiwyg_wysiwyg_include_directory
|
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Wysiwyg API integration for @font-your-face module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_INCLUDE_plugin().
|
||||
*/
|
||||
function fontyourface_wysiwyg_fontyourface_plugin() {
|
||||
|
||||
$plugins = array();
|
||||
|
||||
$fonts = fontyourface_get_fonts();
|
||||
|
||||
$fonts_setting = array();
|
||||
|
||||
foreach ($fonts as $font) {
|
||||
|
||||
$fonts_setting[] = array(
|
||||
'fid' => $font->fid,
|
||||
'name' => $font->name,
|
||||
);
|
||||
|
||||
} // foreach
|
||||
|
||||
$plugins['fontyourface'] = array(
|
||||
'title' => t('@font-your-face'),
|
||||
'vendor url' => 'http://drupal.org/project/fontyourface',
|
||||
'icon file' => 'fontyourface.jpg',
|
||||
'icon title' => t('Set font'),
|
||||
'css path' => 'sites/default/files/fontyourface',
|
||||
'css file' => 'wysiwyg.css',
|
||||
'settings' => array(
|
||||
'fonts' => $fonts_setting,
|
||||
),
|
||||
);
|
||||
|
||||
return $plugins;
|
||||
|
||||
} // fontyourface_wysiwyg_fontyourface_plugin
|
||||
|
@@ -0,0 +1,98 @@
|
||||
(function ($) {
|
||||
|
||||
Drupal.wysiwyg.plugins.fontyourface = {
|
||||
|
||||
/**
|
||||
* Returns whether the passed node belongs to this plugin.
|
||||
*/
|
||||
isNode: function(node) {
|
||||
return true;
|
||||
}, // isNode
|
||||
|
||||
/**
|
||||
* Execute the button.
|
||||
*/
|
||||
invoke: function(data, settings, instanceId) {
|
||||
|
||||
var button = $('#cke_' + instanceId + ' .cke_button_fontyourface');
|
||||
var position = button.offset();
|
||||
var fontSelect = $('<div id="' + instanceId + '_fontyourface-select" class="fontyourface-select"><ul><li data-fid="0">-- NONE --</li></ul></div>');
|
||||
|
||||
fontSelect.data('instanceId', instanceId);
|
||||
fontSelect.data('data', data);
|
||||
|
||||
for (i in settings.fonts) {
|
||||
|
||||
var font = settings.fonts[i];
|
||||
|
||||
$('<li data-fid="' + font.fid + '">' + font.name + '</li>').appendTo(fontSelect.find('ul'));
|
||||
|
||||
} // for
|
||||
|
||||
fontSelect.find('li').click(function() {
|
||||
|
||||
var li = $(this);
|
||||
var div = li.parents('div.fontyourface-select');
|
||||
var data = div.data('data');
|
||||
var instanceId = div.data('instanceId');
|
||||
var fid = li.attr('data-fid');
|
||||
|
||||
if (fid > 0) {
|
||||
|
||||
if (data.format == 'html') {
|
||||
var content = '<span class="fontyourface-' + fid + '">' + data.content + '</span>';
|
||||
} // if
|
||||
else {
|
||||
var content = '<span class="fontyourface-' + fid + '">' + data.content + '</span>';
|
||||
} // else
|
||||
|
||||
if (typeof content != 'undefined') {
|
||||
Drupal.wysiwyg.instances[instanceId].insert(content);
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
div.remove();
|
||||
|
||||
});
|
||||
|
||||
fontSelect.css({
|
||||
'position': 'absolute',
|
||||
'top': position.top + button.height(),
|
||||
'left': position.left,
|
||||
'border': '1px #999 solid',
|
||||
'background': '#fff'
|
||||
});
|
||||
fontSelect.find('ul').css({
|
||||
'list-style': 'none',
|
||||
'margin': '0'
|
||||
});
|
||||
fontSelect.find('li')
|
||||
.css({
|
||||
'margin': '0',
|
||||
'padding': '5px'
|
||||
})
|
||||
.hover(
|
||||
function() {
|
||||
$(this).css('background', '#ccc');
|
||||
},
|
||||
function() {
|
||||
$(this).css('background', '#fff');
|
||||
}
|
||||
);
|
||||
|
||||
fontSelect.appendTo('body');
|
||||
|
||||
}, // invoke
|
||||
|
||||
attach: function(content, settings, instanceId) {
|
||||
return content;
|
||||
}, // attach
|
||||
|
||||
detach: function(content, settings, instanceId) {
|
||||
return content;
|
||||
} // detach
|
||||
|
||||
};
|
||||
|
||||
})(jQuery);
|
Binary file not shown.
After Width: | Height: | Size: 7.5 KiB |
@@ -0,0 +1,14 @@
|
||||
name = Google Fonts API
|
||||
description = @font-your-face provider with Google fonts.
|
||||
dependencies[] = fontyourface
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
|
||||
files[] = views/google_fonts_api.views_default.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Removes fonts on disable.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function google_fonts_api_enable() {
|
||||
|
||||
// Set weight to 1 to ensure google_fonts_api_preprocess_html() is executed after
|
||||
// fontyourface_preprocess_html(), which has weight of 0.
|
||||
db_update('system')
|
||||
->fields(array('weight' => 1))
|
||||
->condition('name', 'google_fonts_api')
|
||||
->execute();
|
||||
|
||||
// Import/update fonts
|
||||
fontyourface_import_fonts('google_fonts_api');
|
||||
|
||||
} // google_fonts_api_enable
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function google_fonts_api_disable() {
|
||||
|
||||
fontyourface_provider_disable('google_fonts_api');
|
||||
|
||||
} // google_fonts_api_disable
|
||||
|
||||
/**
|
||||
* Implements hook_update_N().
|
||||
*/
|
||||
function google_fonts_api_update_7100() {
|
||||
|
||||
// Fonts need to be re-imported after change in issue #1123340.
|
||||
|
||||
drupal_load('module', 'google_fonts_api');
|
||||
|
||||
google_fonts_api_fontyourface_import();
|
||||
|
||||
} // google_fonts_api_update_7100
|
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_info().
|
||||
*/
|
||||
function google_fonts_api_fontyourface_info() {
|
||||
|
||||
$info = array(
|
||||
'name' => 'Google',
|
||||
'url' => 'http://code.google.com/webfonts',
|
||||
'base_path' => 'http://www.google.com/webfonts/family?family=',
|
||||
);
|
||||
|
||||
return $info;
|
||||
|
||||
} // google_fonts_api_fontyourface_info
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_preview().
|
||||
*/
|
||||
function google_fonts_api_fontyourface_preview($font, $text = NULL, $size = 18) {
|
||||
|
||||
$output = '';
|
||||
|
||||
if ($text == NULL) {
|
||||
$text = $font->name;
|
||||
} // if
|
||||
|
||||
if ($size == 'all') {
|
||||
|
||||
// Display variety of sizes.
|
||||
|
||||
$sizes = array(32, 24, 18, 14, 12, 10);
|
||||
|
||||
foreach ($sizes as $size) {
|
||||
|
||||
$output .= '<div style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</div>';
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
// Display single size.
|
||||
|
||||
$output = '<span style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</span>';
|
||||
|
||||
} // else
|
||||
|
||||
return $output;
|
||||
|
||||
} // google_fonts_api_fontyourface_preview
|
||||
|
||||
/**
|
||||
* Implements template_preprocess_html().
|
||||
*/
|
||||
function google_fonts_api_preprocess_html(&$vars) {
|
||||
if (!empty($vars['fontyourface'])) {
|
||||
|
||||
$paths = array();
|
||||
$subsets = array();
|
||||
|
||||
foreach ($vars['fontyourface'] as $used_font) {
|
||||
|
||||
if ($used_font->provider == 'google_fonts_api') {
|
||||
|
||||
$metadata = unserialize($used_font->metadata);
|
||||
|
||||
$path_parts = explode(':', $metadata['path']);
|
||||
|
||||
$subsets[$path_parts[0]][$metadata['subset']] = $metadata['subset'];
|
||||
$all_subsets[$metadata['subset']] = $metadata['subset'];
|
||||
|
||||
if (!isset($paths[$path_parts[0]])) {
|
||||
$paths[$path_parts[0]] = array();
|
||||
} // if
|
||||
|
||||
if (count($path_parts) > 1) {
|
||||
$paths[$path_parts[0]][$path_parts[1]] = $path_parts[1];
|
||||
} // if
|
||||
else {
|
||||
$paths[$path_parts[0]]['regular'] = 'regular';
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
if (count($paths) > 0) {
|
||||
|
||||
$families = array();
|
||||
|
||||
foreach ($paths as $family => $variants) {
|
||||
$families[$family] = urlencode($family) . ':' . implode(',', $variants);
|
||||
} // foreach
|
||||
|
||||
if (module_exists('google_webfont_loader_api')) {
|
||||
|
||||
foreach ($families as $family => $family_with_variants) {
|
||||
|
||||
$font_info = array(
|
||||
'name' => 'Google ' . $family,
|
||||
'google_families' => array($family_with_variants . ':' . implode(',', $subsets[$family])),
|
||||
);
|
||||
|
||||
_google_webfont_loader_api_load_font($font_info);
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
$base = 'http://fonts.googleapis.com/css?family=';
|
||||
|
||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||
$base = 'https://fonts.googleapis.com/css?family=';
|
||||
} // if
|
||||
|
||||
$url = $base . implode('|', $families) . '&subset=' . implode(',', $all_subsets);
|
||||
|
||||
fontyourface_add_css_in_preprocess($vars, $url, 'remote');
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
} // google_fonts_api_preprocess_html
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_import().
|
||||
*/
|
||||
function google_fonts_api_fontyourface_import() {
|
||||
|
||||
// Return the JSON object with all available fonts
|
||||
// For now, it uses the API key of BarisW (co-maintainer of this module)
|
||||
|
||||
// This key is limited to 10.000 requests per day, which should
|
||||
// be sufficient as it is only used when selecting fonts in the
|
||||
// admin interface. After that, the fonts are cached in Drupal.
|
||||
|
||||
$success = TRUE;
|
||||
$fonts = array();
|
||||
|
||||
$result = drupal_http_request('https://www.googleapis.com/webfonts/v1/webfonts?key=' . variable_get('google_fonts_api_key', 'AIzaSyBgeqKlFdYj3Y7VwmrEXnXzpnx5TfKXG4o'));
|
||||
|
||||
fontyourface_log('drupal_http_request response: @response', array('@response' => print_r($result, TRUE)));
|
||||
|
||||
if ($result->code != 200) {
|
||||
|
||||
$success = FALSE;
|
||||
drupal_set_message(t('The list of Google Fonts could not be fetched. Verify that your server can connect the Google Servers (https://www.googleapis.com). Error: %error', array('%error' => $result->error)), 'error');
|
||||
|
||||
} //if
|
||||
elseif (isset($result->data)) {
|
||||
|
||||
$json_results = json_decode($result->data);
|
||||
|
||||
fontyourface_log('google_fonts_api_fontyourface_import JSON: @json', array('@json' => print_r($json_results, TRUE)));
|
||||
|
||||
$fonts = _google_fonts_api_convert_api_results($json_results->items);
|
||||
|
||||
fontyourface_log('google_fonts_api_fontyourface_import fonts: @fonts', array('@fonts' => print_r($fonts, TRUE)));
|
||||
|
||||
} //elseif
|
||||
|
||||
foreach ($fonts as $font) {
|
||||
|
||||
if (!isset($font->tags)) {
|
||||
$font->tags = array();
|
||||
} // if
|
||||
fontyourface_save_font($font);
|
||||
|
||||
} // foreach
|
||||
|
||||
return $success;
|
||||
|
||||
} // google_fonts_api_fontyourface_import
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function google_fonts_api_views_api() {
|
||||
|
||||
if (module_exists('fontyourface_ui')) {
|
||||
|
||||
return array(
|
||||
'api' => 2,
|
||||
'path' => drupal_get_path('module', 'google_fonts_api') . '/views',
|
||||
);
|
||||
|
||||
} // if
|
||||
|
||||
} // google_fonts_api_views_api
|
||||
|
||||
/**
|
||||
* Converts the Google Fonts API JSON results to a generic Fonts object array
|
||||
*
|
||||
* @param $json_font_list: Array of Font objects
|
||||
*
|
||||
*/
|
||||
function _google_fonts_api_convert_api_results($json_font_list) {
|
||||
$fonts = array();
|
||||
foreach ($json_font_list as $json_font) {
|
||||
foreach ($json_font->variants as $json_font_variant) {
|
||||
foreach ($json_font->subsets as $json_font_subset) {
|
||||
|
||||
$font_id = $json_font->family . ' ' . $json_font_variant . ' (' . $json_font_subset . ')';
|
||||
|
||||
switch ($json_font_variant) {
|
||||
case 'regular':
|
||||
$css_style = 'normal';
|
||||
$css_weight = 'normal';
|
||||
break;
|
||||
|
||||
case 'italic':
|
||||
$css_style = 'italic';
|
||||
$css_weight = 'normal';
|
||||
break;
|
||||
|
||||
case 'bold':
|
||||
$css_style = 'normal';
|
||||
$css_weight = 'bold';
|
||||
break;
|
||||
|
||||
case 'bolditalic':
|
||||
$css_style = 'italic';
|
||||
$css_weight = 'bold';
|
||||
break;
|
||||
|
||||
default:
|
||||
// For all other cases (eg 400 or 400italic)
|
||||
if (is_numeric($json_font_variant)) {
|
||||
// Variant is a number, like 400
|
||||
$css_style = 'normal';
|
||||
$css_weight = $json_font_variant;
|
||||
} //if
|
||||
elseif (is_numeric(substr($json_font_variant, 0, 3))){
|
||||
// Variant is a combined string of number and string, like 400italic
|
||||
// The numberic part is always three characters long, so we can split it easily
|
||||
$css_style = substr($json_font_variant, 3);
|
||||
$css_weight = substr($json_font_variant, 0, 3);
|
||||
} //elseif
|
||||
} //switch
|
||||
|
||||
$fonts[$font_id] = new stdClass;
|
||||
$fonts[$font_id]->name = $font_id;
|
||||
$fonts[$font_id]->url = 'http://www.google.com/webfonts/family?family=' . $json_font->family . '&subset=' . $json_font_subset . '#' . $json_font_variant;
|
||||
$fonts[$font_id]->provider = 'google_fonts_api';
|
||||
$fonts[$font_id]->css_family = $json_font->family;
|
||||
$fonts[$font_id]->css_style = $css_style;
|
||||
$fonts[$font_id]->css_weight = $css_weight;
|
||||
$fonts[$font_id]->foundry = '';
|
||||
$fonts[$font_id]->foundry_url = '';
|
||||
$fonts[$font_id]->license = '';
|
||||
$fonts[$font_id]->license_url = '';
|
||||
$fonts[$font_id]->metadata = serialize(array('path' => $json_font->family . ':' . $json_font_variant, 'subset' => $json_font_subset));
|
||||
|
||||
foreach($json_font->subsets as $subset) {
|
||||
$tag_object = new StdClass;
|
||||
$tag_object->type = 'subset';
|
||||
$tag_object->name = $subset;
|
||||
$fonts[$font_id]->tags[] = $tag_object;
|
||||
} //foreach
|
||||
|
||||
} //foreach
|
||||
} //foreach
|
||||
} //foreach
|
||||
|
||||
return $fonts;
|
||||
|
||||
} // _google_fonts_api_convert_api_results
|
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Adds default views.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_default_views().
|
||||
*/
|
||||
function google_fonts_api_views_default_views() {
|
||||
/*
|
||||
* View 'google_fonts_api_browse'
|
||||
*/
|
||||
$view = new view;
|
||||
$view->name = 'google_fonts_api_browse';
|
||||
$view->description = 'Browsing interface for fonts.';
|
||||
$view->tag = '@font-your-face';
|
||||
$view->base_table = 'fontyourface_font';
|
||||
$view->human_name = 'Google Fonts API Browse';
|
||||
$view->core = 0;
|
||||
$view->api_version = '3.0';
|
||||
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
||||
|
||||
/* Display: Defaults */
|
||||
$handler = $view->new_display('default', 'Defaults', 'default');
|
||||
$handler->display->display_options['title'] = 'Browse fonts';
|
||||
$handler->display->display_options['css_class'] = 'view-fontyourface-browse';
|
||||
$handler->display->display_options['use_ajax'] = TRUE;
|
||||
$handler->display->display_options['access']['type'] = 'perm';
|
||||
$handler->display->display_options['access']['perm'] = 'administer @font-your-face';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['distinct'] = TRUE;
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE;
|
||||
$handler->display->display_options['exposed_form']['options']['autosubmit'] = 1;
|
||||
$handler->display->display_options['exposed_form']['options']['autosubmit_hide'] = 0;
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '50';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['pager']['options']['id'] = '0';
|
||||
$handler->display->display_options['pager']['options']['expose']['items_per_page_options_all'] = 0;
|
||||
$handler->display->display_options['style_plugin'] = 'list';
|
||||
$handler->display->display_options['style_options']['row_class'] = 'font';
|
||||
$handler->display->display_options['style_options']['class'] = 'fonts-listing';
|
||||
$handler->display->display_options['style_options']['wrapper_class'] = '';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Header: Global: Text area */
|
||||
$handler->display->display_options['header']['area']['id'] = 'area';
|
||||
$handler->display->display_options['header']['area']['table'] = 'views';
|
||||
$handler->display->display_options['header']['area']['field'] = 'area';
|
||||
$handler->display->display_options['header']['area']['empty'] = TRUE;
|
||||
$handler->display->display_options['header']['area']['content'] = '0 fonts currently enabled.';
|
||||
$handler->display->display_options['header']['area']['format'] = 'filtered_html';
|
||||
$handler->display->display_options['header']['area']['tokenize'] = 0;
|
||||
/* Relationship: Font: Font Tag */
|
||||
$handler->display->display_options['relationships']['tid']['id'] = 'tid';
|
||||
$handler->display->display_options['relationships']['tid']['table'] = 'fontyourface_tag_font';
|
||||
$handler->display->display_options['relationships']['tid']['field'] = 'tid';
|
||||
$handler->display->display_options['relationships']['tid']['required'] = 0;
|
||||
/* Field: Font: Name */
|
||||
$handler->display->display_options['fields']['name_1']['id'] = 'name_1';
|
||||
$handler->display->display_options['fields']['name_1']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['name_1']['field'] = 'name';
|
||||
$handler->display->display_options['fields']['name_1']['label'] = '';
|
||||
$handler->display->display_options['fields']['name_1']['exclude'] = TRUE;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['alter_text'] = 1;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['text'] = '<span>Edit</span>';
|
||||
$handler->display->display_options['fields']['name_1']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['name_1']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['name_1']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['name_1']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name_1']['link_to_font'] = 'edit';
|
||||
$handler->display->display_options['fields']['name_1']['display_as'] = '0';
|
||||
/* Field: Font: Font ID */
|
||||
$handler->display->display_options['fields']['fid']['id'] = 'fid';
|
||||
$handler->display->display_options['fields']['fid']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['fid']['field'] = 'fid';
|
||||
$handler->display->display_options['fields']['fid']['label'] = '';
|
||||
$handler->display->display_options['fields']['fid']['exclude'] = TRUE;
|
||||
$handler->display->display_options['fields']['fid']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['fid']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['fid']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['fid']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['fid']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['fid']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['fid']['separator'] = '';
|
||||
$handler->display->display_options['fields']['fid']['format_plural'] = 0;
|
||||
/* Field: Font: Enabled Yes/No */
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['id'] = 'enabled_yes_no';
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['field'] = 'enabled_yes_no';
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['label'] = '';
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['exclude'] = TRUE;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['element_default_classes'] = 1;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['enabled_yes_no']['hide_alter_empty'] = 1;
|
||||
/* Field: Font: Name */
|
||||
$handler->display->display_options['fields']['name']['id'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['name']['field'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['label'] = '';
|
||||
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 1;
|
||||
$handler->display->display_options['fields']['name']['alter']['text'] = '<div class="fontyourface-header enabled-[enabled_yes_no]"><h4>[name]</h4> [name_1]</div>';
|
||||
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['name']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['name']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['name']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['name']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name']['link_to_font'] = '0';
|
||||
$handler->display->display_options['fields']['name']['display_as'] = '0';
|
||||
/* Field: Font: Enable/Disable */
|
||||
$handler->display->display_options['fields']['enable_disable_link']['id'] = 'enable_disable_link';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['field'] = 'enable_disable_link';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['label'] = '';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['alter_text'] = 1;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['text'] = '<div class="fontyourface-footer enabled-[enabled_yes_no]" data-fid="[fid]">[enable_disable_link]</div>';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['enable_disable_link']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['enable_disable_link']['hide_alter_empty'] = 0;
|
||||
/* Field: Font: Preview */
|
||||
$handler->display->display_options['fields']['preview']['id'] = 'preview';
|
||||
$handler->display->display_options['fields']['preview']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['fields']['preview']['field'] = 'preview';
|
||||
$handler->display->display_options['fields']['preview']['label'] = '';
|
||||
$handler->display->display_options['fields']['preview']['alter']['alter_text'] = 1;
|
||||
$handler->display->display_options['fields']['preview']['alter']['text'] = '<div class="fontyourface-preview enabled-[enabled_yes_no]">[preview]</div>';
|
||||
$handler->display->display_options['fields']['preview']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['preview']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['preview']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['element_type'] = '0';
|
||||
$handler->display->display_options['fields']['preview']['element_label_colon'] = FALSE;
|
||||
$handler->display->display_options['fields']['preview']['element_wrapper_type'] = '0';
|
||||
$handler->display->display_options['fields']['preview']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['preview']['hide_alter_empty'] = 0;
|
||||
/* Sort criterion: Font: Name */
|
||||
$handler->display->display_options['sorts']['name']['id'] = 'name';
|
||||
$handler->display->display_options['sorts']['name']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['sorts']['name']['field'] = 'name';
|
||||
/* Contextual filter: Font: Provider */
|
||||
$handler->display->display_options['arguments']['provider']['id'] = 'provider';
|
||||
$handler->display->display_options['arguments']['provider']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['arguments']['provider']['field'] = 'provider';
|
||||
$handler->display->display_options['arguments']['provider']['title_enable'] = 1;
|
||||
$handler->display->display_options['arguments']['provider']['title'] = 'Browse fonts: %1';
|
||||
$handler->display->display_options['arguments']['provider']['breadcrumb_enable'] = 1;
|
||||
$handler->display->display_options['arguments']['provider']['breadcrumb'] = '@font-your-face %1';
|
||||
$handler->display->display_options['arguments']['provider']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['provider']['default_argument_skip_url'] = 0;
|
||||
$handler->display->display_options['arguments']['provider']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['provider']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['provider']['summary_options']['items_per_page'] = '25';
|
||||
$handler->display->display_options['arguments']['provider']['glossary'] = 0;
|
||||
$handler->display->display_options['arguments']['provider']['limit'] = '0';
|
||||
$handler->display->display_options['arguments']['provider']['transform_dash'] = 0;
|
||||
$handler->display->display_options['arguments']['provider']['break_phrase'] = 0;
|
||||
/* Filter criterion: Font: Name */
|
||||
$handler->display->display_options['filters']['name']['id'] = 'name';
|
||||
$handler->display->display_options['filters']['name']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['name']['field'] = 'name';
|
||||
$handler->display->display_options['filters']['name']['operator'] = 'contains';
|
||||
$handler->display->display_options['filters']['name']['group'] = 0;
|
||||
$handler->display->display_options['filters']['name']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['name']['expose']['operator_id'] = 'name_op';
|
||||
$handler->display->display_options['filters']['name']['expose']['label'] = 'Name';
|
||||
$handler->display->display_options['filters']['name']['expose']['operator'] = 'name_op';
|
||||
$handler->display->display_options['filters']['name']['expose']['identifier'] = 'name';
|
||||
/* Filter criterion: Tag */
|
||||
$handler->display->display_options['filters']['tid_3']['id'] = 'tid_3';
|
||||
$handler->display->display_options['filters']['tid_3']['table'] = 'fontyourface_tag';
|
||||
$handler->display->display_options['filters']['tid_3']['field'] = 'tid';
|
||||
$handler->display->display_options['filters']['tid_3']['relationship'] = 'tid';
|
||||
$handler->display->display_options['filters']['tid_3']['ui_name'] = 'Tag';
|
||||
$handler->display->display_options['filters']['tid_3']['group'] = 0;
|
||||
$handler->display->display_options['filters']['tid_3']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['operator_id'] = 'tid_3_op';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['label'] = 'Tag';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['operator'] = 'tid_3_op';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['identifier'] = 'tag_id';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['reduce'] = 0;
|
||||
$handler->display->display_options['filters']['tid_3']['reduce_duplicates'] = 0;
|
||||
$handler->display->display_options['filters']['tid_3']['type'] = 'select';
|
||||
$handler->display->display_options['filters']['tid_3']['tag_type'] = 'tag';
|
||||
/* Filter criterion: Font: Foundry */
|
||||
$handler->display->display_options['filters']['foundry']['id'] = 'foundry';
|
||||
$handler->display->display_options['filters']['foundry']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['foundry']['field'] = 'foundry';
|
||||
$handler->display->display_options['filters']['foundry']['group'] = 0;
|
||||
$handler->display->display_options['filters']['foundry']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['foundry']['expose']['operator_id'] = 'foundry_op';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['label'] = 'Foundry';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['operator'] = 'foundry_op';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['identifier'] = 'foundry';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['reduce'] = 0;
|
||||
/* Filter criterion: Font: License */
|
||||
$handler->display->display_options['filters']['license']['id'] = 'license';
|
||||
$handler->display->display_options['filters']['license']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['license']['field'] = 'license';
|
||||
$handler->display->display_options['filters']['license']['operator'] = 'contains';
|
||||
$handler->display->display_options['filters']['license']['group'] = 0;
|
||||
$handler->display->display_options['filters']['license']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['license']['expose']['operator_id'] = 'license_op';
|
||||
$handler->display->display_options['filters']['license']['expose']['label'] = 'License';
|
||||
$handler->display->display_options['filters']['license']['expose']['operator'] = 'license_op';
|
||||
$handler->display->display_options['filters']['license']['expose']['identifier'] = 'license';
|
||||
$handler->display->display_options['filters']['license']['expose']['required'] = 0;
|
||||
$handler->display->display_options['filters']['license']['expose']['multiple'] = FALSE;
|
||||
|
||||
/* Display: Google Fonts */
|
||||
$handler = $view->new_display('page', 'Google Fonts', 'page_2');
|
||||
$handler->display->display_options['defaults']['arguments'] = FALSE;
|
||||
$handler->display->display_options['defaults']['filters'] = FALSE;
|
||||
/* Filter criterion: Font: Name */
|
||||
$handler->display->display_options['filters']['name']['id'] = 'name';
|
||||
$handler->display->display_options['filters']['name']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['name']['field'] = 'name';
|
||||
$handler->display->display_options['filters']['name']['operator'] = 'contains';
|
||||
$handler->display->display_options['filters']['name']['group'] = 0;
|
||||
$handler->display->display_options['filters']['name']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['name']['expose']['operator_id'] = 'name_op';
|
||||
$handler->display->display_options['filters']['name']['expose']['label'] = 'Name';
|
||||
$handler->display->display_options['filters']['name']['expose']['operator'] = 'name_op';
|
||||
$handler->display->display_options['filters']['name']['expose']['identifier'] = 'name';
|
||||
/* Filter criterion: Tag */
|
||||
$handler->display->display_options['filters']['tid_3']['id'] = 'tid_3';
|
||||
$handler->display->display_options['filters']['tid_3']['table'] = 'fontyourface_tag';
|
||||
$handler->display->display_options['filters']['tid_3']['field'] = 'tid';
|
||||
$handler->display->display_options['filters']['tid_3']['relationship'] = 'tid';
|
||||
$handler->display->display_options['filters']['tid_3']['ui_name'] = 'Tag';
|
||||
$handler->display->display_options['filters']['tid_3']['group'] = 0;
|
||||
$handler->display->display_options['filters']['tid_3']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['operator_id'] = 'tid_3_op';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['label'] = 'Tag';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['operator'] = 'tid_3_op';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['identifier'] = 'tag_id';
|
||||
$handler->display->display_options['filters']['tid_3']['expose']['reduce'] = 0;
|
||||
$handler->display->display_options['filters']['tid_3']['reduce_duplicates'] = 0;
|
||||
$handler->display->display_options['filters']['tid_3']['type'] = 'select';
|
||||
$handler->display->display_options['filters']['tid_3']['tag_type'] = 'tag';
|
||||
/* Filter criterion: Subset */
|
||||
$handler->display->display_options['filters']['tid']['id'] = 'tid';
|
||||
$handler->display->display_options['filters']['tid']['table'] = 'fontyourface_tag';
|
||||
$handler->display->display_options['filters']['tid']['field'] = 'tid';
|
||||
$handler->display->display_options['filters']['tid']['relationship'] = 'tid';
|
||||
$handler->display->display_options['filters']['tid']['ui_name'] = 'Subset';
|
||||
$handler->display->display_options['filters']['tid']['group'] = 0;
|
||||
$handler->display->display_options['filters']['tid']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['tid']['expose']['operator_id'] = 'tid_op';
|
||||
$handler->display->display_options['filters']['tid']['expose']['label'] = 'Subset';
|
||||
$handler->display->display_options['filters']['tid']['expose']['operator'] = 'tid_op';
|
||||
$handler->display->display_options['filters']['tid']['expose']['identifier'] = 'subset_id';
|
||||
$handler->display->display_options['filters']['tid']['expose']['reduce'] = 0;
|
||||
$handler->display->display_options['filters']['tid']['reduce_duplicates'] = 0;
|
||||
$handler->display->display_options['filters']['tid']['type'] = 'select';
|
||||
$handler->display->display_options['filters']['tid']['tag_type'] = 'subset';
|
||||
/* Filter criterion: Font: Foundry */
|
||||
$handler->display->display_options['filters']['foundry']['id'] = 'foundry';
|
||||
$handler->display->display_options['filters']['foundry']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['foundry']['field'] = 'foundry';
|
||||
$handler->display->display_options['filters']['foundry']['group'] = 0;
|
||||
$handler->display->display_options['filters']['foundry']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['foundry']['expose']['operator_id'] = 'foundry_op';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['label'] = 'Foundry';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['operator'] = 'foundry_op';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['identifier'] = 'foundry';
|
||||
$handler->display->display_options['filters']['foundry']['expose']['reduce'] = 0;
|
||||
/* Filter criterion: Font: License */
|
||||
$handler->display->display_options['filters']['license']['id'] = 'license';
|
||||
$handler->display->display_options['filters']['license']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['license']['field'] = 'license';
|
||||
$handler->display->display_options['filters']['license']['operator'] = 'contains';
|
||||
$handler->display->display_options['filters']['license']['group'] = 0;
|
||||
$handler->display->display_options['filters']['license']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['license']['expose']['operator_id'] = 'license_op';
|
||||
$handler->display->display_options['filters']['license']['expose']['label'] = 'License';
|
||||
$handler->display->display_options['filters']['license']['expose']['operator'] = 'license_op';
|
||||
$handler->display->display_options['filters']['license']['expose']['identifier'] = 'license';
|
||||
$handler->display->display_options['filters']['license']['expose']['required'] = 0;
|
||||
$handler->display->display_options['filters']['license']['expose']['multiple'] = FALSE;
|
||||
/* Filter criterion: Font: Provider */
|
||||
$handler->display->display_options['filters']['provider']['id'] = 'provider';
|
||||
$handler->display->display_options['filters']['provider']['table'] = 'fontyourface_font';
|
||||
$handler->display->display_options['filters']['provider']['field'] = 'provider';
|
||||
$handler->display->display_options['filters']['provider']['value'] = array(
|
||||
'google_fonts_api' => 'google_fonts_api',
|
||||
);
|
||||
$handler->display->display_options['path'] = 'admin/appearance/fontyourface/browse/google_fonts_api';
|
||||
$handler->display->display_options['menu']['type'] = 'tab';
|
||||
$handler->display->display_options['menu']['title'] = 'Google Fonts';
|
||||
$handler->display->display_options['menu']['weight'] = '0';
|
||||
$translatables['google_fonts_api_browse'] = array(
|
||||
t('Defaults'),
|
||||
t('Browse fonts'),
|
||||
t('more'),
|
||||
t('Apply'),
|
||||
t('Reset'),
|
||||
t('Sort by'),
|
||||
t('Asc'),
|
||||
t('Desc'),
|
||||
t('Items per page'),
|
||||
t('- All -'),
|
||||
t('Offset'),
|
||||
t('0 fonts currently enabled.'),
|
||||
t('Font Tag'),
|
||||
t('<span>Edit</span>'),
|
||||
t('.'),
|
||||
t('<div class="fontyourface-header enabled-[enabled_yes_no]"><h4>[name]</h4> [name_1]</div>'),
|
||||
t('<div class="fontyourface-footer enabled-[enabled_yes_no]" data-fid="[fid]">[enable_disable_link]</div>'),
|
||||
t('<div class="fontyourface-preview enabled-[enabled_yes_no]">[preview]</div>'),
|
||||
t('All'),
|
||||
t('Browse fonts: %1'),
|
||||
t('@font-your-face %1'),
|
||||
t('Name'),
|
||||
t('Tag'),
|
||||
t('Foundry'),
|
||||
t('License'),
|
||||
t('Google Fonts'),
|
||||
t('Subset'),
|
||||
);
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
return $views;
|
||||
|
||||
} // google_fonts_api_views_default_views
|
@@ -0,0 +1,12 @@
|
||||
name = Local Fonts
|
||||
description = @font-your-face provider with fonts installed locally on the Drupal server.
|
||||
dependencies[] = fontyourface
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Removes fonts on disable.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function local_fonts_enable() {
|
||||
|
||||
// Set weight to 1 to ensure local_fonts_preprocess_html() is executed after
|
||||
// fontyourface_preprocess_html(), which has weight of 0.
|
||||
db_update('system')
|
||||
->fields(array('weight' => 1))
|
||||
->condition('name', 'local_fonts')
|
||||
->execute();
|
||||
|
||||
} // local_fonts_enable
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function local_fonts_disable() {
|
||||
|
||||
fontyourface_provider_disable('local_fonts');
|
||||
|
||||
} // local_fonts_disable
|
||||
|
||||
/**
|
||||
* Update local fonts metadata.
|
||||
*/
|
||||
function local_fonts_update_7200() {
|
||||
$fonts = fontyourface_get_fonts($where = "provider = 'local_fonts'");
|
||||
if (!$fonts) {
|
||||
return NULL;
|
||||
}
|
||||
foreach ($fonts as $font) {
|
||||
$metadata = unserialize($font->metadata);
|
||||
if (isset($metadata['font_uri'])) {
|
||||
unset($metadata['font_uri']);
|
||||
}
|
||||
$dirname = drupal_dirname($metadata['path']);
|
||||
if ($handle = opendir($dirname)) {
|
||||
while ($file_name = readdir($handle)) {
|
||||
if (preg_match("/\.ttf/i", $file_name) == 1) {
|
||||
$metadata['font_uri']['truetype'] = $dirname . '/' . $file_name;
|
||||
}
|
||||
if (preg_match("/\.eot/i", $file_name) == 1) {
|
||||
$metadata['font_uri']['eot'] = $dirname . '/' . $file_name;
|
||||
}
|
||||
if (preg_match("/\.woff/i", $file_name) == 1) {
|
||||
$metadata['font_uri']['woff'] = $dirname . '/' . $file_name;
|
||||
}
|
||||
if (preg_match("/\.svg/i", $file_name) == 1) {
|
||||
$metadata['font_uri']['svg'] = $dirname . '/' . $file_name;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
$font->metadata = serialize($metadata);
|
||||
fontyourface_save_font($font);
|
||||
}
|
||||
}
|
@@ -0,0 +1,511 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_info().
|
||||
*/
|
||||
function local_fonts_fontyourface_info() {
|
||||
|
||||
return array(
|
||||
'name' => t('Local Fonts'),
|
||||
'url' => 'http://drupal.org/project/fontyourface#local',
|
||||
'base_path' => 'public://fontyourface/local_fonts/',
|
||||
);
|
||||
|
||||
} // local_fonts_fontyourface_info
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function local_fonts_menu() {
|
||||
|
||||
$items = array();
|
||||
|
||||
$items['admin/config/user-interface/fontyourface/local_fonts'] = array(
|
||||
'title' => 'Import Local Font',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('local_fonts_add_form'),
|
||||
'access arguments' => array('administer @font-your-face'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
|
||||
$items['admin/appearance/fontyourface/local_fonts/delete/%'] = array(
|
||||
'title' => 'Delete Local Font',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('local_fonts_delete_form', 5),
|
||||
'access arguments' => array('administer @font-your-face'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
|
||||
} // local_fonts_menu
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function local_fonts_form_alter(&$form, &$form_state, $form_id) {
|
||||
|
||||
if ($form_id == 'fontyourface_settings_form') {
|
||||
|
||||
// Replace button with a link to the custom font form.
|
||||
$form['providers']['local_fonts_import']['import'] = array(
|
||||
'#type' => 'item',
|
||||
'#markup' => l(t('Import Local Font'), 'admin/config/user-interface/fontyourface/local_fonts'),
|
||||
);
|
||||
|
||||
} // if
|
||||
elseif ($form_id == 'fontyourface_ui_admin_edit_form') {
|
||||
|
||||
$font = fontyourface_get_font($form['fid']['#value']);
|
||||
|
||||
// Add delete button for local fonts.
|
||||
|
||||
if ($font->provider == 'local_fonts') {
|
||||
|
||||
$form['buttons']['delete'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Delete font record'),
|
||||
'#submit' => array('local_fonts_delete_button_submit'),
|
||||
);
|
||||
|
||||
} // if
|
||||
|
||||
} // elseif
|
||||
|
||||
} // local_fonts_form_fontyourface_settings_form_alter
|
||||
|
||||
/**
|
||||
* Redirect to delete confirmation form.
|
||||
*/
|
||||
function local_fonts_delete_button_submit($form, &$form_state) {
|
||||
|
||||
$destination = '';
|
||||
if (isset($_GET['destination'])) {
|
||||
$destination = drupal_get_destination();
|
||||
unset($_GET['destination']);
|
||||
}
|
||||
$form_state['redirect'] = array('admin/appearance/fontyourface/local_fonts/delete/' . $form['fid']['#value'], $destination);
|
||||
|
||||
} // local_fonts_delete_button_submit
|
||||
|
||||
/**
|
||||
* Form for submitting a local font.
|
||||
*/
|
||||
function local_fonts_add_form($form, $form_state) {
|
||||
|
||||
$form = array();
|
||||
|
||||
$form['local_fonts']['information'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Font Information'),
|
||||
'#collapsible' => FALSE,
|
||||
'#description' => t('If you want to use this font on text that can have mark-up, make sure to add all used variants (like regular, bold, italic and bold/italic).'),
|
||||
);
|
||||
|
||||
$form['local_fonts']['information']['css_family'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('CSS Font Family'),
|
||||
'#description' => t('Add the plain Font Family name here, eg <em>My Special Font</em>, without the style or weight.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['local_fonts']['information']['css_style'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('CSS Font Style'),
|
||||
'#options' => array(
|
||||
'normal' => t('Normal'),
|
||||
'italic' => t('Italic'),
|
||||
'oblique' => t('Oblique'),
|
||||
),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['local_fonts']['information']['css_weight'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('CSS Font Weight'),
|
||||
'#options' => array(
|
||||
'normal' => t('Normal'),
|
||||
'bold' => t('Bold'),
|
||||
'bolder' => t('Bolder'),
|
||||
'lighter' => t('Lighter'),
|
||||
'100' => t('100'),
|
||||
'200' => t('200'),
|
||||
'300' => t('300'),
|
||||
'400' => t('400'),
|
||||
'500' => t('500'),
|
||||
'600' => t('600'),
|
||||
'700' => t('700'),
|
||||
'800' => t('800'),
|
||||
'900' => t('900'),
|
||||
),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['local_fonts']['upload']['eot'] = array(
|
||||
'#type' => 'file',
|
||||
'#title' => t('EOT font file'),
|
||||
'#description' => t('Embedded Open Type. This format is supported by IE 5-8.'),
|
||||
);
|
||||
|
||||
$form['local_fonts']['upload']['ttf'] = array(
|
||||
'#type' => 'file',
|
||||
'#title' => t('TTF font file'),
|
||||
'#description' => t('Raw TrueType file, designed to look good on-screen. This format is supported by Webkit/Safari 3.1+, Safari Mobile iOS 4.2+, Opera 10+, Mozilla/Firefox 3.5+, and Chrome 4+'),
|
||||
);
|
||||
|
||||
$form['local_fonts']['upload']['woff'] = array(
|
||||
'#type' => 'file',
|
||||
'#title' => t('WOFF font file'),
|
||||
'#description' => t('Web-only font format that uses gzip compression. This format is supported by IE9+, FF3.6+, Chrome 5+.'),
|
||||
);
|
||||
|
||||
$form['local_fonts']['upload']['svg'] = array(
|
||||
'#type' => 'file',
|
||||
'#title' => t('SVG font file'),
|
||||
'#description' => t('An XML format required by iOS devices before version 4.2. Currently supported by iOS 4.1 and below, and Opera 10+.'),
|
||||
);
|
||||
|
||||
$form = confirm_form($form, t('Import Local Font'), 'admin/config/user-interface/fontyourface', '');
|
||||
$form['#attributes'] = array('enctype' => 'multipart/form-data');
|
||||
|
||||
return $form;
|
||||
|
||||
} // local_fonts_add_form
|
||||
|
||||
/**
|
||||
* Implements hook_form_validate().
|
||||
*/
|
||||
function local_fonts_add_form_validate($form, &$form_state) {
|
||||
|
||||
// Ensure a font family with the same results does not exist in the database.
|
||||
|
||||
$values = $form_state['values'];
|
||||
$font_path = strtr(preg_replace('#[^a-zA-Z0-9]+#', ' ', $values['css_family']), ' ', '_') . '-' . $values['css_style'] . '-' . $values['css_weight'];
|
||||
$font_style = $values['css_style'];
|
||||
$font_weight = $values['css_weight'];
|
||||
$local_fonts_directory = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/fontyourface/local_fonts';
|
||||
$destination_directory = $local_fonts_directory . '/' . $font_path;
|
||||
|
||||
$file_uploaded = FALSE;
|
||||
|
||||
if (
|
||||
(file_prepare_directory($local_fonts_directory, FILE_CREATE_DIRECTORY)) &&
|
||||
(file_prepare_directory($destination_directory, FILE_CREATE_DIRECTORY))
|
||||
) {
|
||||
|
||||
// Validate the files against their extension
|
||||
|
||||
$files = $_FILES['files']['name'];
|
||||
|
||||
foreach ($files as $key => $filename) {
|
||||
|
||||
$file_object = new stdClass;
|
||||
$file_object->filename = $filename;
|
||||
|
||||
if (!empty($file_object->filename)) {
|
||||
|
||||
$validation = file_validate_extensions($file_object, $key);
|
||||
|
||||
if (is_array($validation) && count($validation) > 0) {
|
||||
form_set_error($key, implode(', ', $validation));
|
||||
} // if
|
||||
else {
|
||||
$file_uploaded = TRUE;
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
else {
|
||||
form_set_error('files', t('Error creating file directory.'));
|
||||
} // else
|
||||
|
||||
if (!$file_uploaded) {
|
||||
form_set_error('files', t('Upload at least one font file to go with the font family.'));
|
||||
} // if
|
||||
|
||||
} // local_fonts_add_form_validate
|
||||
|
||||
/**
|
||||
* Implements hook_form_submit().
|
||||
*/
|
||||
function local_fonts_add_form_submit($form, &$form_state) {
|
||||
|
||||
$stream_wrappers = file_get_stream_wrappers();
|
||||
if($stream_wrappers['public']) {
|
||||
$scheme = 'public';
|
||||
}
|
||||
|
||||
$values = $form_state['values'];
|
||||
$font_path = strtr(preg_replace('#[^a-zA-Z0-9]+#', ' ', $values['css_family']), ' ', '_') . '-' . $values['css_style'] . '-' . $values['css_weight'];
|
||||
$font_family = $values['css_family'];
|
||||
$font_style = $values['css_style'];
|
||||
$font_weight = $values['css_weight'];
|
||||
$local_fonts_directory = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/fontyourface/local_fonts';
|
||||
$destination_directory = $local_fonts_directory . '/' . $font_path;
|
||||
|
||||
$validators['file_validate_extensions'][] = 'eot ttf svg woff css';
|
||||
|
||||
$files = $_FILES['files']['name'];
|
||||
|
||||
$combined_sources = array();
|
||||
$src = '';
|
||||
|
||||
if (
|
||||
(file_prepare_directory($local_fonts_directory, FILE_CREATE_DIRECTORY)) &&
|
||||
(file_prepare_directory($destination_directory, FILE_CREATE_DIRECTORY))
|
||||
) {
|
||||
|
||||
$destination_directory = $scheme . '://' . 'fontyourface/local_fonts/' . $font_path;
|
||||
$destination_css_file = $destination_directory . '/stylesheet.css';
|
||||
$destination_font_files = array();
|
||||
|
||||
foreach ($files as $key => $filename) {
|
||||
|
||||
$format = $key;
|
||||
|
||||
// Everything but TTF matches the extension.
|
||||
|
||||
if ($format == 'ttf') {
|
||||
$format = 'truetype';
|
||||
} // if
|
||||
|
||||
if (!empty($filename)) {
|
||||
|
||||
if ($file = file_save_upload($key, $validators, $destination_directory, FILE_EXISTS_REPLACE)) {
|
||||
|
||||
// Copy the temporary file to permanent location.
|
||||
|
||||
$file->status = FILE_STATUS_PERMANENT;
|
||||
$file = file_save($file);
|
||||
$destination_font_files[$format] = $destination_directory . '/' . $file->filename;
|
||||
|
||||
if ($format == 'eot') {
|
||||
|
||||
// EOT gets special treatment to trick IE
|
||||
// into working right.
|
||||
|
||||
$src .= ' src: url("' . $file->filename . '");' . "\n";
|
||||
$combined_sources[] = 'url("' . $file->filename . '?#iefix") format("embedded-opentype")';
|
||||
|
||||
} // if
|
||||
elseif ($format == 'svg') {
|
||||
|
||||
// Get the font ID from the SVG file.
|
||||
$svg = file_get_contents($file->uri);
|
||||
$hash = '';
|
||||
|
||||
if (preg_match('#<font([^>]+)>#i', $svg, $font_tag_match)) {
|
||||
|
||||
if (preg_match('#id="([^"]+)"#i', $font_tag_match[1], $id_match)) {
|
||||
$hash = $id_match[1];
|
||||
} // if
|
||||
elseif (preg_match("#id='([^']+)'#i", $font_tag_match[1], $id_match)) {
|
||||
$hash = $id_match[1];
|
||||
} // elseif
|
||||
|
||||
} // if
|
||||
|
||||
$url = $file->filename . '#' . $hash;
|
||||
$combined_sources[] = 'url("' . $url . '") format("' . $format . '")';
|
||||
|
||||
} // elseif
|
||||
else {
|
||||
|
||||
$combined_sources[] = 'url("' . $file->filename . '") format("' . $format . '")';
|
||||
|
||||
} // else
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
if (count($combined_sources) > 0) {
|
||||
|
||||
// Add a fake local font name first to prevent name conflicts with local fonts.
|
||||
|
||||
$src .= ' src: ' . implode(', ', $combined_sources) . ';' . "\n";
|
||||
|
||||
} // if
|
||||
|
||||
$generated_css = '@font-face {' . "\n";
|
||||
$generated_css .= " font-family: '" . $font_family . "';" . "\n";
|
||||
$generated_css .= $src;
|
||||
$generated_css .= ' font-style: ' . $font_style . ';' . "\n";
|
||||
$generated_css .= ' font-weight: ' . $font_weight . ';' . "\n";
|
||||
$generated_css .= '}' . "\n";
|
||||
$css_file = file_unmanaged_save_data($generated_css, $destination_css_file, FILE_EXISTS_REPLACE);
|
||||
|
||||
$local_font = new stdClass;
|
||||
$local_font->name = $font_family . ' ' . $font_style . ' ' . $font_weight;
|
||||
$local_font->url = 'http://localhost/#' . md5($local_font->name);
|
||||
$local_font->css_family = $font_family;
|
||||
$local_font->css_style = $font_style;
|
||||
$local_font->css_weight = $font_weight;
|
||||
$local_font->provider = 'local_fonts';
|
||||
$local_font->metadata = serialize(
|
||||
array(
|
||||
'path' => $destination_css_file,
|
||||
'font_uri' => $destination_font_files,
|
||||
)
|
||||
);
|
||||
$local_font->tags = array();
|
||||
|
||||
fontyourface_save_font($local_font);
|
||||
|
||||
drupal_set_message(t('@font added. Make sure to enable it before you can use it.', array('@font' => $font_family)));
|
||||
|
||||
} // if
|
||||
|
||||
drupal_goto('admin/config/user-interface/fontyourface');
|
||||
|
||||
} // local_fonts_add_form_submit
|
||||
|
||||
/**
|
||||
* Form for deleting a local font.
|
||||
*/
|
||||
function local_fonts_delete_form($form, $form_state, $fid) {
|
||||
|
||||
$font = fontyourface_get_font($fid);
|
||||
|
||||
$form = array(
|
||||
'fid' => array(
|
||||
'#type' => 'value',
|
||||
'#value' => $fid,
|
||||
),
|
||||
'confirm' => array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Confirm delete of @title?', array('@title' => $font->name)), array(
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Delete font record',
|
||||
), array(
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Cancel',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $form;
|
||||
|
||||
} // local_fonts_delete_form
|
||||
|
||||
/**
|
||||
* Handles submission of delete form.
|
||||
*/
|
||||
function local_fonts_delete_form_submit($form, &$form_state) {
|
||||
|
||||
if ($form_state['input']['op'] == t('Cancel')) {
|
||||
|
||||
drupal_goto('admin/appearance/fontyourface/edit/' . $form['fid']['#value']);
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
$font = fontyourface_get_font($form['fid']['#value']);
|
||||
local_fonts_delete_font($font);
|
||||
|
||||
drupal_set_message(t('@font deleted.', array('@font' => $font->name)));
|
||||
drupal_goto('admin/appearance/fontyourface');
|
||||
|
||||
} // else
|
||||
|
||||
} // local_fonts_delete_form_submit
|
||||
|
||||
/**
|
||||
* Deletes given font.
|
||||
*/
|
||||
function local_fonts_delete_font($font) {
|
||||
|
||||
// Bail out if attempting to delete a non-local font.
|
||||
|
||||
if ($font->provider != 'local_fonts') {
|
||||
drupal_set_message(t('This is not a local font and cannot be deleted.'));
|
||||
return TRUE;
|
||||
} // if
|
||||
|
||||
$metadata = unserialize($font->metadata);
|
||||
|
||||
$directory = dirname($metadata['path']);
|
||||
|
||||
// Delete all the files.
|
||||
|
||||
$files = scandir($directory);
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
if ($file != '.' && $file != '..') {
|
||||
unlink($directory . '/' . $file);
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
// Delete the directory.
|
||||
|
||||
rmdir($directory);
|
||||
|
||||
// Delete from the database.
|
||||
|
||||
db_delete('fontyourface_font')
|
||||
->condition('fid', $font->fid)
|
||||
->execute();
|
||||
|
||||
fontyourface_delete_unused_tags();
|
||||
|
||||
return TRUE;
|
||||
|
||||
} // local_fonts_delete_font
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_preview().
|
||||
*/
|
||||
function local_fonts_fontyourface_preview($font, $text = NULL, $size = 18) {
|
||||
$output = '';
|
||||
if ($text == NULL) {
|
||||
$text = $font->name;
|
||||
}
|
||||
if ($size == 'all') {
|
||||
// Display variety of sizes.
|
||||
$sizes = array(32, 24, 18, 14, 12, 10);
|
||||
foreach ($sizes as $size) {
|
||||
$output .= '<div style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</div>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Display single size.
|
||||
$output = '<span style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</span>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements template_preprocess_html().
|
||||
*/
|
||||
function local_fonts_preprocess_html(&$vars) {
|
||||
|
||||
if (!empty($vars['fontyourface'])) {
|
||||
|
||||
foreach ($vars['fontyourface'] as $used_font) {
|
||||
|
||||
if ($used_font->provider == 'local_fonts') {
|
||||
$metadata = unserialize($used_font->metadata);
|
||||
if (module_exists('google_webfont_loader_api')) {
|
||||
$font_info = array(
|
||||
'custom_families' => array($used_font->css_family),
|
||||
'custom_style_css' => array($metadata['path']),
|
||||
);
|
||||
_google_webfont_loader_api_load_font($font_info);
|
||||
}
|
||||
else {
|
||||
fontyourface_add_css_in_preprocess($vars, $metadata['path'], FALSE);
|
||||
}
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
|
||||
} // local_fonts_preprocess_html
|
@@ -0,0 +1,12 @@
|
||||
name = Typekit API
|
||||
description = @font-your-face provider with Typekit.com fonts.
|
||||
dependencies[] = fontyourface
|
||||
package = @font-your-face
|
||||
core = 7.x
|
||||
php = 5.2.0
|
||||
; Information added by drupal.org packaging script on 2012-11-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "fontyourface"
|
||||
datestamp = "1352782302"
|
||||
|
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Removes fonts on disable.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function typekit_api_enable() {
|
||||
|
||||
// Set weight to 1 to ensure typekit_api_preprocess_html() is executed after
|
||||
// fontyourface_preprocess_html(), which has weight of 0.
|
||||
db_update('system')
|
||||
->fields(array('weight' => 1))
|
||||
->condition('name', 'typekit_api')
|
||||
->execute();
|
||||
|
||||
} // typekit_api_enable
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function typekit_api_disable() {
|
||||
|
||||
fontyourface_provider_disable('typekit_api');
|
||||
|
||||
} // typekit_api_disable
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function typekit_api_uninstall() {
|
||||
|
||||
variable_del('typekit_api_token');
|
||||
|
||||
} // typekit_api_uninstall
|
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
|
||||
define('TYPEKIT_API_BASE_URL', 'https://typekit.com/api/v1/json/');
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_info().
|
||||
*/
|
||||
function typekit_api_fontyourface_info() {
|
||||
|
||||
return array(
|
||||
'name' => 'Typekit',
|
||||
'url' => 'http://typekit.com/',
|
||||
'base_path' => 'http://typekit.com/fonts/',
|
||||
);
|
||||
|
||||
return $info;
|
||||
|
||||
} // typekit_api_fontyourface_info
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_import().
|
||||
*/
|
||||
function typekit_api_fontyourface_import() {
|
||||
|
||||
$success = TRUE;
|
||||
$kits = typekit_api_get_kits();
|
||||
|
||||
fontyourface_log('Imported Typekit kits: @kits', array('@kits' => print_r($kits, TRUE)));
|
||||
|
||||
foreach ($kits as $kit) {
|
||||
|
||||
$kit_info = typekit_api_get_kit($kit->id);
|
||||
|
||||
fontyourface_log('Imported Typekit kit info: @kit', array('@kit' => print_r($kit_info, TRUE)));
|
||||
|
||||
if (typekit_api_kit_matches_domain($kit_info, $_SERVER['HTTP_HOST'])) {
|
||||
|
||||
foreach ($kit_info->families as $family_info) {
|
||||
|
||||
foreach ($family_info->variations as $variant_index => $variant_id) {
|
||||
|
||||
$variant = typekit_api_get_variant($family_info->id, $variant_id);
|
||||
|
||||
fontyourface_log('Imported Typekit variant info: @variant', array('@variant' => print_r($variant, TRUE)));
|
||||
|
||||
$metadata = array(
|
||||
'typekit_id' => $variant->id,
|
||||
'variant' => $variant->font_variant,
|
||||
'kit' => $kit_info->id,
|
||||
);
|
||||
|
||||
$font = new stdClass;
|
||||
$font->name = $variant->name;
|
||||
$font->url = 'http://typekit.com/fonts/' . $family_info->slug . '#' . $variant_id;
|
||||
$font->provider = 'typekit_api';
|
||||
$font->enabled = 1;
|
||||
$font->metadata = serialize($metadata);
|
||||
// Enclose each family name in single quotes.
|
||||
$font->css_family = "'" . implode("', '", $family_info->css_names) . "'";
|
||||
$font->css_style = $variant->font_style;
|
||||
$font->css_weight = $variant->font_weight;
|
||||
$font->foundry = $variant->foundry->name;
|
||||
$font->foundry_url = 'http://typekit.com/foundries/' . $variant->foundry->slug;
|
||||
$font->tags = array();
|
||||
|
||||
fontyourface_save_font($font);
|
||||
|
||||
} // foreach
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
else {
|
||||
$success = FALSE;
|
||||
fontyourface_log('Typekit kit did not match current domain, @domain', array('@domain' => $_SERVER['HTTP_HOST']));
|
||||
}
|
||||
} // foreach
|
||||
|
||||
return $success;
|
||||
|
||||
} // typekit_api_fontyourface_import
|
||||
|
||||
/**
|
||||
* Implements template_preprocess_html().
|
||||
*/
|
||||
function typekit_api_preprocess_html(&$vars) {
|
||||
|
||||
if (!empty($vars['fontyourface'])) {
|
||||
|
||||
$kits = array();
|
||||
|
||||
foreach ($vars['fontyourface'] as $used_font) {
|
||||
|
||||
if ($used_font->provider == 'typekit_api') {
|
||||
|
||||
$metadata = unserialize($used_font->metadata);
|
||||
$kits[$metadata['kit']] = TRUE;
|
||||
|
||||
} // if
|
||||
|
||||
} // foreach
|
||||
|
||||
if (count($kits) > 0) {
|
||||
|
||||
$base = 'http://use.typekit.com/';
|
||||
|
||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||
$base = 'https://use.typekit.com/';
|
||||
} // if
|
||||
|
||||
foreach (array_keys($kits) as $kit) {
|
||||
|
||||
drupal_add_js($base . $kit . '.js', array('type' => 'external'));
|
||||
$variables['scripts'] = drupal_get_js();
|
||||
|
||||
} // foreach
|
||||
|
||||
drupal_add_js('try{Typekit.load();}catch(e){}', array('type' => 'inline'));
|
||||
$vars['scripts'] = drupal_get_js();
|
||||
|
||||
} // if
|
||||
|
||||
} // if
|
||||
|
||||
} // typekit_api_preprocess_html
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function typekit_api_form_alter(&$form, &$form_state, $form_id) {
|
||||
|
||||
if ($form_id == 'fontyourface_ui_settings_form') {
|
||||
|
||||
$form['typekit_api'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Typekit',
|
||||
'#weight' => -1,
|
||||
'typekit_api_token' => array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('TypeKit API token'),
|
||||
'#description' => t('Provided at ') . l('Typekit.com/account/tokens', 'https://typekit.com/account/tokens'),
|
||||
'#default_value' => variable_get('typekit_api_token', ''),
|
||||
),
|
||||
'typekit_api_save' => array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save TypeKit API token'),
|
||||
),
|
||||
);
|
||||
|
||||
// Move the default update/import button to the Typekit fieldset
|
||||
if (isset($form['providers']['typekit_api_import'])) {
|
||||
$form['typekit_api']['typekit_api_import'] = $form['providers']['typekit_api_import'];
|
||||
unset($form['providers']['typekit_api_import']);
|
||||
}
|
||||
|
||||
$form['#submit'][] = 'typekit_api_token_submit';
|
||||
|
||||
} // if
|
||||
|
||||
} // typekit_api_form_alter
|
||||
|
||||
/**
|
||||
* Updates API token.
|
||||
*/
|
||||
function typekit_api_token_submit($form, &$form_state) {
|
||||
|
||||
if ($form_state['clicked_button']['#parents'][0] == 'typekit_api_save') {
|
||||
|
||||
variable_set('typekit_api_token', $form_state['values']['typekit_api_token']);
|
||||
drupal_set_message(t('Typeit API token updated.'));
|
||||
|
||||
} // if
|
||||
|
||||
} // typekit_api_token_submit
|
||||
|
||||
/**
|
||||
* Implements hook_fontyourface_preview().
|
||||
*/
|
||||
function typekit_api_fontyourface_preview($font, $text = NULL, $size = 18) {
|
||||
|
||||
$output = '';
|
||||
|
||||
if ($text == NULL) {
|
||||
$text = $font->name;
|
||||
} // if
|
||||
|
||||
if ($size == 'all') {
|
||||
|
||||
// Display variety of sizes.
|
||||
|
||||
$sizes = array(32, 24, 18, 14, 12, 10);
|
||||
|
||||
foreach ($sizes as $size) {
|
||||
|
||||
$output .= '<div style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</div>';
|
||||
|
||||
} // foreach
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
// Display single size.
|
||||
|
||||
$output = '<span style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</span>';
|
||||
|
||||
} // else
|
||||
|
||||
return $output;
|
||||
|
||||
} // typekit_api_fontyourface_preview
|
||||
|
||||
/**
|
||||
* Provides header with token.
|
||||
*/
|
||||
function typekit_api_token_headers() {
|
||||
|
||||
return array('X-Typekit-Token' => variable_get('typekit_api_token', ''));
|
||||
|
||||
} // typekit_api_token_headers
|
||||
|
||||
/**
|
||||
* Gets list of kits from API.
|
||||
*/
|
||||
function typekit_api_get_kits() {
|
||||
|
||||
$kits = array();
|
||||
|
||||
$response = drupal_http_request(TYPEKIT_API_BASE_URL . 'kits', array('headers' => typekit_api_token_headers()));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
$kits = $data->kits;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error importing kit list from Typekit.'), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $kits;
|
||||
|
||||
} // typekit_api_get_kits
|
||||
|
||||
/**
|
||||
* Get a specific kit from API based on ID.
|
||||
*/
|
||||
function typekit_api_get_kit($kit_id) {
|
||||
|
||||
$response = drupal_http_request(TYPEKIT_API_BASE_URL . 'kits/' . $kit_id, array('headers' => typekit_api_token_headers()));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
$kit = $data->kit;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error importing a kit (@kit) from Typekit.', array('@kit' => $kit_id)), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $kit;
|
||||
|
||||
} // typekit_api_get_kit
|
||||
|
||||
/**
|
||||
* Checks if a given kit matches a given domain.
|
||||
*/
|
||||
function typekit_api_kit_matches_domain($kit, $domain) {
|
||||
|
||||
$domain = drupal_strtolower($domain);
|
||||
|
||||
foreach ($kit->domains as $kit_domain) {
|
||||
|
||||
$kit_domain = drupal_strtolower($kit_domain);
|
||||
|
||||
if ($kit_domain == $domain) {
|
||||
return TRUE;
|
||||
} // if
|
||||
else {
|
||||
|
||||
$regex = '#' . str_replace(array('.', '*'), array('\.', '.*'), $kit_domain) . '#';
|
||||
|
||||
if (preg_match($regex, $domain)) {
|
||||
return TRUE;
|
||||
} // if
|
||||
|
||||
} // else
|
||||
|
||||
} // foreach
|
||||
|
||||
return FALSE;
|
||||
|
||||
} // typekit_api_kit_matches_domain
|
||||
|
||||
/**
|
||||
* Get a specific variant from API based on family and variant IDs.
|
||||
*/
|
||||
function typekit_api_get_variant($family_id, $variant_id) {
|
||||
|
||||
$response = drupal_http_request(TYPEKIT_API_BASE_URL . 'families/' . $family_id . '/' . $variant_id, array('headers' => typekit_api_token_headers()));
|
||||
|
||||
if ($response->code == 200) {
|
||||
|
||||
$data = json_decode($response->data);
|
||||
$variant = $data->variation;
|
||||
|
||||
} // if
|
||||
else {
|
||||
|
||||
drupal_set_message(t('There was an error importing a variant (@kit, @variant) from Typekit.', array('@kit' => $kit_id, '@variant' => $variant_id)), 'error');
|
||||
fontyourface_log('Invalid drupal_http_request response: @response', array('@response' => print_r($response, TRUE)));
|
||||
|
||||
} // else
|
||||
|
||||
return $variant;
|
||||
|
||||
} // typekit_api_get_variant
|
Reference in New Issue
Block a user