first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
To install Piecemaker place the unzipped module in the sites/all/modules directory
Next download to the Drupal piecemaker package from github.com at:
https://github.com/arcaneadam/Piecemaker-Drupal
Make sure to select the Branch version that matches the module version.
For example:
Module -> Package
-------------------
7.x-1.1 -> 7.x-1.x
-------------------
7.x-2.1 -> 7.x-2.x

View File

@@ -0,0 +1,274 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
Cambridge, MA 02139, 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 Library 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

View File

View File

@@ -0,0 +1,23 @@
(function ($) {
Drupal.behaviors.Piecemaker = {
attach: function (context, settings) {
$.each(settings.Piecemaker, function($id, $piecemaker) {
Drupal.Piecemaker.embed($id, $piecemaker, settings);
});
}
}
Drupal.Piecemaker = {
embed: function($id, $piecemaker, settings) {
$attributes = {
id: $id + '-flash',
styleclass: 'piecemaker ' + $id + '-style',
name: $id,
};
$url = settings.Piecemaker_URI + '/piecemaker.swf';
swfobject.embedSWF($url , $id, $piecemaker.width, $piecemaker.height, '10', false, $piecemaker.flashvars,
$piecemaker.params, $attributes);
},
}
})(jQuery);

View File

@@ -0,0 +1,9 @@
.piecemaker-opt-wrap > div > div,
.fvimage {
margin-left: 15px !important;
}
.radios-left > div {float:left; padding-right: 15px !important;}
.radios-left {clear:both;}
.piecemaker-opt-wrap {clear:both;}

View File

@@ -0,0 +1,597 @@
<?php
/**
* @file
*
*/
/**
* Form builder for the add block form.
*
* @see piecemaker_add_block_form_validate()
* @see piecemaker_add_block_form_submit()
* @ingroup forms
*/
function piecemaker_add_block_form($form, &$form_state, $delta = 0) {
if (!empty($form_state['submitted']) && !empty($form_state['rebuild'])) {
unset($form_state['values']['file']['add'], $form_state['input']['file']['add']);
}
$form_state_clone = &drupal_static('piecemaker_blocks_block_form');
$form_state_clone = $form_state;
module_load_include('inc', 'block', 'block.admin');
return block_admin_configure($form, $form_state, 'piecemaker_blocks', $delta);
}
/**
* Form validation handler for the add block form.
*
* @see piecemaker_add_block_form()
* @see piecemaker_add_block_form_submit()
*/
function piecemaker_add_block_form_validate($form, &$form_state) {
$form_state_clone = &drupal_static('piecemaker_blocks_block_form');
$form_state_clone = $form_state;
$custom_block_exists = (bool) db_query_range('SELECT 1 FROM {piecemaker_blocks} WHERE info = :info AND bid != :bid', 0, 1, array(':info' => $form_state['values']['info'], ':bid' => $form_state['values']['delta']))->fetchField();
if (empty($form_state['values']['info']) || $custom_block_exists) {
form_set_error('info', t('Ensure that each block description is unique.'));
}
}
/**
* Form submission handler for the add block form.
*
* Saves the new custom block.
*
* @see piecemaker_add_block_form()
* @see piecemaker_add_block_form_validate()
*/
function piecemaker_add_block_form_submit($form, &$form_state) {
$form_state_clone = &drupal_static('piecemaker_blocks_block_form');
if (!empty($form_state['values']['delta'])) {
module_load_include('inc', 'block', 'block.admin');
block_admin_configure_submit($form, $form_state);
}
else {
piecemaker_add_new_block_form_submit($form, $form_state);
}
$form_state_clone = $form_state;
}
/**
* Form callback for adding a new block
*/
function piecemaker_add_new_block_form_submit($form, &$form_state) {
$query = db_insert('piecemaker_blocks');
$delta = $query
->fields(array(
'info' => $form_state['values']['info'],
'pid' => $form_state['values']['pid'],
))
->execute();
$files = $form_state['values']['file'];
unset($files['add']);
uasort($files, 'drupal_sort_weight');
$i = 0;
foreach ($files as $weight => $file) {
$values = array(
'fid' => $file['media']['fid'],
'bid' => $delta,
'weight' => $i,
'data' => $file['options'],
'type' => $file['type'],
);
$bfid = drupal_write_record('piecemaker_blocks_files', $values);
$i++;
}
// Store block delta to allow other modules to work with new block.
$form_state['values']['delta'] = $delta;
$query = db_insert('block')->fields(array('visibility', 'pages', 'custom', 'title', 'module', 'theme', 'status', 'weight', 'delta', 'cache'));
foreach (list_themes() as $key => $theme) {
if ($theme->status) {
$query->values(array(
'visibility' => (int) $form_state['values']['visibility'],
'pages' => trim($form_state['values']['pages']),
'custom' => (int) $form_state['values']['custom'],
'title' => $form_state['values']['title'],
'module' => $form_state['values']['module'],
'theme' => $theme->name,
'status' => 0,
'weight' => 0,
'delta' => $delta,
'cache' => DRUPAL_NO_CACHE,
));
}
}
$query->execute();
$query = db_insert('block_role')->fields(array('rid', 'module', 'delta'));
foreach (array_filter($form_state['values']['roles']) as $rid) {
$query->values(array(
'rid' => $rid,
'module' => $form_state['values']['module'],
'delta' => $delta,
));
}
$query->execute();
// Store regions per theme for this block
foreach ($form_state['values']['regions'] as $theme => $region) {
db_merge('block')
->key(array('theme' => $theme, 'delta' => $delta, 'module' => $form_state['values']['module']))
->fields(array(
'region' => ($region == BLOCK_REGION_NONE ? '' : $region),
'pages' => trim($form_state['values']['pages']),
'status' => (int) ($region != BLOCK_REGION_NONE),
))
->execute();
}
drupal_set_message(t('The block has been created.'));
cache_clear_all();
$form_state['redirect'] = 'admin/structure/block';
}
/**
* Form Handler for saving existing blocks
*/
function piecemaker_save_block_form_submit($delta, $edit) {
$query = db_update('piecemaker_blocks');
$query->condition('bid', $delta);
$result = $query
->fields(array(
'info' => $edit['info'],
'pid' => $edit['pid'],
))
->execute();
$num_deleted = db_delete('piecemaker_blocks_files')
->condition('bid', $delta)
->execute();
$files = $edit['file'];
unset($files['add']);
uasort($files, 'drupal_sort_weight');
$i = 0;
foreach ($files as $weight => $file) {
$values = array(
'fid' => $file['media']['fid'],
'bid' => $delta,
'weight' => $i,
'data' => $file['options'],
'type' => $file['type'],
);
$bfid = drupal_write_record('piecemaker_blocks_files', $values);
$i++;
}
}
/**
* Define the custom block form.
*/
function piecemaker_blocks_block_form($edit = array()) {
$form_state = &drupal_static(__FUNCTION__);
$edit += array(
'info' => '',
'files' => array(),
'pid' => '',
);
$form['#attached']['css'][] = drupal_get_path('module', 'piecemaker_blocks') . '/css/admin.css';
$form['info'] = array(
'#type' => 'textfield',
'#title' => t('Block description'),
'#default_value' => $edit['info'],
'#maxlength' => 64,
'#description' => t('A brief description of your block. Used on the <a href="@overview">Blocks administration page</a>.', array('@overview' => url('admin/structure/block'))),
'#required' => TRUE,
'#weight' => -19,
);
$form['pid'] = array(
'#type' => 'select',
'#title' => t('Piecemaker Profile'),
'#options' => piecemaker_profile_options(),
'#default_value' => array($edit['pid']),
'#required' => TRUE,
);
$form['file'] = array(
'#type' => 'fieldset',
'#title' => t('Piecemaker Files'),
'#theme' => 'piecemaker_blocks_files',
'#tree' => TRUE,
'#prefix' => '<div id="files-table">',
'#suffix' => '</div>',
);
$types = array(
'Image' => 'Image',
'Video' => 'Video',
'Flash' => 'Flash',
);
$weights = range(0, 50);
foreach (image_styles() as $stid => $style) {
$image_styles[$stid] = $style['name'];
}
if (isset($form_state['blocks_files'])) {
$edit['files'] = $form_state['blocks_files'];
drupal_set_message('Files and file order are not saved until you save the block.');
}
$i = 1;
foreach($edit['files'] as $key => $file) {
if (!empty($file['bfid'])) {
$form['file'][$key]['bfid'] = array(
'#type' => 'value',
'#value' => $file['bfid'],
);
}
$form['file'][$key]['type'] = array(
'#type' => 'value',
'#value' => $file['type'],
);
$form['file'][$key]['type']['markup']['#markup'] = $file['type'];
$form['file'][$key]['weight'] = array(
'#type' => 'select',
'#options' => $weights,
'#default_value' => array($key),
'#attributes' => array('class' => array('file-weight')),
);
$media_file = file_load($file['media']['fid']);
$form['file'][$key]['media'] = array(
'#markup' => theme('media_admin_thumbnail', array('file' => $media_file, 'style' => 'thumbnail')),
);
$form['file'][$key]['media']['fid'] = array(
'#type' => 'value',
'#value' => $file['media']['fid'],
);
$opts = array();
$opts = $file['options'];
$form['file'][$key]['options']['Title'] = array(
'#type' => 'value',
'#value' => empty($opts['Title']) ? '' : $opts['Title'],
);
$form['file'][$key]['options']['Title']['markup']['#markup'] = empty($opts['Title']) ? 'No Title Provided' : $opts['Title'];
$form['file'][$key]['options'][$file['type']] = array(
'#type' => 'item',
'#title' => t($file['type'] . ' Options'),
'#prefix' => '<div class="piecemaker-opt-wrap">',
'#suffix' => '</div>',
);
if ($file['type'] == 'Image') {
$form['file'][$key]['options']['Image']['style'] = array(
'#type' => 'value',
'#value' => $opts['Image']['style'],
);
$form['file'][$key]['options']['Image']['style']['markup'] = array(
'#type' => 'item',
'#title' => t('Image Style'),
'#markup' => $image_styles[$opts['Image']['style']]
);
$form['file'][$key]['options']['Image']['Text'] = array(
'#type' => 'value',
'#value' => empty($opts['Image']['Text']) ? '' : $opts['Image']['Text'],
);
$form['file'][$key]['options']['Image']['Text']['markup'] = array(
'#type' => 'item',
'#title' => t('Image Text'),
'#markup' => check_markup($opts['Image']['Text']['value'], $opts['Image']['Text']['format']),
);
$form['file'][$key]['options']['Image']['Hyperlink'] = array(
'#type' => 'value',
'#value' => empty($opts['Image']['Hyperlink']) ? '' : $opts['Image']['Hyperlink'],
);
$target = array(
'_self' => 'Same Window/Tab',
'_blank' => 'New Window/Tab',
);
$form['file'][$key]['options']['Image']['Target'] = array(
'#type' => 'value',
'#value' => $opts['Image']['Target'],
);
$form['file'][$key]['options']['Image']['Hyperlink']['markup'] = array(
'#type' => 'item',
'#title' => t('Image Hyperlink'),
'#markup' => l($opts['Image']['Hyperlink'], $opts['Image']['Hyperlink'], array(
'absolute' => TRUE,
'external' => url_is_external($opts['Image']['Hyperlink']),
'attributes' => array(
'target' => $opts['Image']['Target'],
),
)) . ' - Link opens in: ' . $target[$opts['Image']['Target']],
);
}
if ($file['type'] == 'Video') {
$form['file'][$key]['options']['Video']['Width'] = array(
'#type' => 'value',
'#value' => $opts['Video']['Width'],
);
$form['file'][$key]['options']['Video']['Width']['markup'] = array(
'#type' => 'item',
'#title' => t('Video Width'),
'#markup' => $opts['Video']['Width'] . ' pixels',
);
$form['file'][$key]['options']['Video']['Height'] = array(
'#type' => 'value',
'#value' => $opts['Video']['Height'],
);
$form['file'][$key]['options']['Video']['Height']['markup'] = array(
'#type' => 'item',
'#title' => t('Video Height'),
'#markup' => $opts['Video']['Height'] . ' pixels',
);
$autoplay = array('true' => 'On', 'false' => 'Off');
$form['file'][$key]['options']['Video']['Autoplay'] = array(
'#type' => 'value',
'#value' => $opts['Video']['Autoplay'],
);
$form['file'][$key]['options']['Video']['Autoplay']['markup'] = array(
'#type' => 'item',
'#title' => t('Video Autoplay'),
'#markup' => $autoplay[$opts['Video']['Autoplay']],
);
}
if (in_array($file['type'], array('Video', 'Flash')) && $opts['fvimage']['fid'] > 0) {
$bg_file = file_load($opts['fvimage']['fid']);
$form['file'][$key]['options']['fvimage'] = array(
'#type' => 'item',
'#title' => t('Background Image'),
'#markup' => theme('media_admin_thumbnail', array('file' => $bg_file, 'style' => 'thumbnail')),
);
$form['file'][$key]['options']['fvimage']['fid'] = array(
'#type' => 'value',
'#value' => $opts['fvimage']['fid'],
);
}
$form['file'][$key]['action'] = array(
'#type' => 'submit',
'#value' => 'Delete File ' . $i,
'#submit' => array('piecemaker_blocks_delete_file'),
'#ajax' => array(
'callback' => 'piecemaker_blocks_file_ajax',
'wrapper' => 'files-table',
'progress' => array(
'type' => 'throbber',
'message' => t('Deleting file'),
),
'method' => 'replace',
'effect' => 'fade',
),
);
$i++;
}
$form['file']['add']['type'] = array(
'#type' => 'select',
'#options' => $types,
'#default_value' => array('Image'),
'#attributes' => array('class' => array('file-type-select')),
);
$form['file']['add']['weight'] = array(
'#type' => 'select',
'#options' => $weights,
'#default_value' => 50,
'#attributes' => array('class' => array('file-weight')),
);
$form['file']['add']['media'] = array(
'#type' => 'media',
'#title' => '',
'#description' => '',
'#media_options' => array(
'global' => array(
'types' => array('image', 'video', 'other'),
),
)
);
$form['file']['add']['options']['Title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
);
$form['file']['add']['options']['Image'] = array(
'#type' => 'item',
'#title' => t('Image Options'),
'#states' => array(
'visible' => array(
'select.file-type-select' => array('value' => 'Image'),
),
),
'#prefix' => '<div class="piecemaker-opt-wrap">',
'#suffix' => '</div>',
);
$form['file']['add']['options']['Image']['style'] = array(
'#type' => 'select',
'#options' => $image_styles,
'#title' => t('Image Style'),
);
$form['file']['add']['options']['Image']['Text'] = array(
'#type' => 'text_format',
'#title' => t('Text'),
'#cols' => 25,
'#format' => isset($edit['format']) ? $edit['format'] : NULL,
);
$form['file']['add']['options']['Image']['Hyperlink'] = array(
'#type' => 'textfield',
'#title' => t('Hyperlink'),
);
$form['file']['add']['options']['Image']['Target'] = array(
'#type' => 'select',
'#title' => t('Hyperlink Target'),
'#options' => array(
'_self' => 'Same Window/Tab',
'_blank' => 'New Window/Tab',
),
);
$form['file']['add']['options']['Video'] = array(
'#type' => 'item',
'#title' => t('Video Options'),
'#states' => array(
'visible' => array(
'select.file-type-select' => array('value' => 'Video'),
),
),
'#prefix' => '<div class="piecemaker-opt-wrap">',
'#suffix' => '</div>',
);
$form['file']['add']['options']['Video']['Width'] = array(
'#type' => 'textfield',
'#size' => 10,
'#title' => 'Width',
'#field_suffix' => 'pixels',
);
$form['file']['add']['options']['Video']['Height'] = array(
'#type' => 'textfield',
'#size' => 10,
'#title' => 'Height',
'#field_suffix' => 'pixels',
);
$form['file']['add']['options']['Video']['Autoplay'] = array(
'#type' => 'radios',
'#title' => 'Autoplay',
'#options' => array('true' => 'On', 'false' => 'Off'),
'#default_value' => 'true',
'#attributes' => array('class' => array('radios-left')),
);
$form['file']['add']['options']['Flash'] = array(
'#type' => 'item',
'#title' => t('Flash Options'),
'#states' => array(
'visible' => array(
'select.file-type-select' => array('value' => 'Flash'),
),
),
'#prefix' => '<div class="piecemaker-opt-wrap">',
'#suffix' => '</div>',
);
$form['file']['add']['options']['fvimage'] = array(
'#type' => 'media',
'#title' => t('Background Image'),
'#description' => '',
'#states' => array(
'invisible' => array(
'select.file-type-select' => array('value' => 'Image'),
),
),
'#prefix' => '<div class="fvimage">',
'#suffix' => '</div>',
);
$form['file']['add']['action'] = array(
'#type' => 'submit',
'#value' => 'Add File',
'#submit' => array('piecemaker_blocks_add_file'),
'#validate' => array('piecemaker_blocks_add_file_validate'),
'#ajax' => array(
'callback' => 'piecemaker_blocks_file_ajax',
'wrapper' => 'files-table',
'progress' => array(
'type' => 'throbber',
'message' => t('Adding file'),
),
'method' => 'replace',
'effect' => 'fade',
),
);
return $form;
}
/**
* Theme Callback for piecemaker_blocks_files
*/
function theme_piecemaker_blocks_files($vars) {
$form = $vars['form'];
$head = array(
t('Type'),
t('Order'),
t('File'),
t('Options'),
t('Add/Delete File'),
);
foreach(element_children($form) as $key) {
$line = &$form[$key];
$row = array();
$row['data'][] = drupal_render($line['type']);
$row['data'][] = drupal_render($line['weight']);
$row['data'][] = drupal_render($line['media']);
$row['data'][] = drupal_render($line['options']);
$row['data'][] = drupal_render($line['action']);
$row['class'][] = 'draggable';
if ($key == 'add') {
$row['id'][] = 'add-files-row';
}
$tvars['rows'][] = $row;
}
$tvars['header'] = $head;
$tvars['attributes'] = array(
'id' => 'piecemaker-files',
);
$tvars['sticky'] = FALSE;
drupal_add_tabledrag('piecemaker-files', 'order', 'sibling', 'file-weight');
return theme('table', $tvars);
}
/**
* Delete File callback for the block add/edit form
*/
function piecemaker_blocks_delete_file($form, &$form_state) {
$form_state_clone = &drupal_static('piecemaker_blocks_block_form');
$clicked = $form_state['clicked_button'];
$key = $clicked['#parents'][1];
$files = $form_state['values']['file'];
unset($files[$key]);
//Kill the add row since it's not needed;
unset($files['add']);
uasort($files, 'drupal_sort_weight');
foreach ($files as $key => $file) {
unset($file['weight']);
unset($file['action']);
$blocks_files[] = $file;
}
$form_state['blocks_files'] = $blocks_files;
$form_state['rebuild'] = TRUE;
drupal_set_message('File Deleted');
$form_state_clone = $form_state;
}
/**
* Add file callback for the black add/edit form
*/
function piecemaker_blocks_add_file($form, &$form_state) {
$form_state_clone = &drupal_static('piecemaker_blocks_block_form');
$files = $form_state['values']['file'];
uasort($files, 'drupal_sort_weight');
foreach ($files as $key => $file) {
unset($file['weight']);
unset($file['action']);
$blocks_files[] = $file;
}
$form_state['blocks_files'] = $blocks_files;
$form_state['rebuild'] = TRUE;
drupal_set_message('File Added');
$form_state_clone = $form_state;
}
/**
* Add file callback for the black add/edit form
*/
function piecemaker_blocks_add_file_validate($form, &$form_state) {
$form_state_clone = &drupal_static('piecemaker_blocks_block_form');
$file = $form_state['values']['file']['add'];
if (empty($file['media']['fid'])) {
form_set_error('file][add', 'You must select a file');
}
switch ($file['type']) {
case 'Video':
$opt = $file['options']['Video'];
if (empty($opt['Width']) || empty($opt['Height'])) {
form_set_error('file][add][options][Video', 'You must set a Width and Height for all Videos');
}
break;
}
$form_state_clone = $form_state;
}

View File

@@ -0,0 +1,12 @@
name = Piecemaker Blocks
package = Piecemaker
description = Provides Piecemaker blocks.
dependencies[] = piecemaker
dependencies[] = media
core = 7.x
; Information added by drupal.org packaging script on 2011-07-08
version = "7.x-1.0"
core = "7.x"
project = "piecemaker"
datestamp = "1310158319"

View File

@@ -0,0 +1,84 @@
<?php
/**
* @file Install, Update, and Uninstall hooks
*/
/**
* Implements hook_schema
*/
function piecemaker_blocks_schema() {
$schema['piecemaker_blocks'] = array(
'description' => 'Piecemaker blocks',
'fields' => array(
'bid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Block ID',
),
'info' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => 'Block Admin title',
),
'pid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'decsription' => 'Piecemaker Profile ID',
),
),
'primary key' => array('bid'),
);
$schema['piecemaker_blocks_files'] = array(
'description' => 'Piecemaker blocks',
'fields' => array(
'bfid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Block File ID',
),
'bid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'decsription' => 'Block Delta',
),
'fid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'decsription' => 'File ID',
),
'type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
'description' => 'File Type',
),
'weight' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'decsription' => 'File Weight',
),
'data' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
),
),
'primary key' => array('bfid'),
);
return $schema;
}

View File

@@ -0,0 +1,164 @@
<?php
/**
* @file
* Core and Contrib hooks for the Piecemaker Blocks module
*/
/**
* Implements hook_menu().
*/
function piecemaker_blocks_menu() {
$items['admin/structure/block/piecemaker/add'] = array(
'title' => 'Add Piecemaker block',
'page callback' => 'drupal_get_form',
'page arguments' => array('piecemaker_add_block_form'),
'access arguments' => array('administer blocks'),
'type' => MENU_LOCAL_ACTION,
'file' => 'piecemaker_blocks.admin.inc',
);
$items['admin/structure/block/piecemaker/edit/%'] = array(
'title' => 'Configure Block',
'page callback' => 'drupal_get_form',
'page arguments' => array('piecemaker_add_block_form', 5),
'access arguments' => array('administer blocks'),
'file' => 'piecemaker_blocks.admin.inc',
);
$items['admin/structure/block/piecemaker/edit/%/configure'] = array(
'title' => 'Configure block',
'type' => MENU_DEFAULT_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
);
return $items;
}
/**
* Implements hook_piecemaker_handler()
*/
function piecemaker_blocks_piecemaker_handler() {
return array(
'piecemaker_blocks' => array(
'callback' => 'piecemaker_blocks_xml_build',
'access' => 'piecemaker_blocks_access',
),
);
}
/**
* Implements hook_block_info().
*/
function piecemaker_blocks_block_info() {
$blocks = array();
$result = db_query('SELECT bid, info FROM {piecemaker_blocks} ORDER BY info');
foreach ($result as $block) {
$blocks[$block->bid]['info'] = t('Piecemaker: ') . $block->info;
// Not worth caching.
$blocks[$block->bid]['cache'] = DRUPAL_NO_CACHE;
}
return $blocks;
}
/**
* Implements hook_block_configure().
*/
function piecemaker_blocks_block_configure($delta = 0) {
if ($delta) {
$custom_block = piecemaker_blocks_block_get($delta);
}
else {
$custom_block = array();
}
module_load_include('inc', 'piecemaker_blocks', 'piecemaker_blocks.admin');
return piecemaker_blocks_block_form($custom_block);
}
/**
* Implements hook_block_save().
*/
function piecemaker_blocks_block_save($delta = 0, $edit = array()) {
module_load_include('inc', 'piecemaker_blocks', 'piecemaker_blocks.admin');
piecemaker_save_block_form_submit($delta, $edit);
}
/**
* Implements hook_block_view().
*
* Generates the administrator-defined blocks for display.
*/
function piecemaker_blocks_block_view($delta = '') {
$block = piecemaker_blocks_block_get($delta);
$profile = piecemaker_profile_load($block['pid']);
$vars = array(
'handler' => 'piecemaker_blocks',
'key' => $delta,
'profile' => $profile,
);
$data['subject'] = NULL;
$data['content'] = theme('piecemaker', $vars);
return $data;
}
/**
* Implements hook_theme()
*/
function piecemaker_blocks_theme() {
$path = drupal_get_path('module', 'piecemaker_blocks');
return array(
'piecemaker_blocks_files' => array(
'render element' => 'form',
'path' => $path,
'file' => 'piecemaker_blocks.admin.inc',
),
);
}
/**
* Gets the block elements for a piecemaker Block
*/
function piecemaker_blocks_block_get($delta) {
$blocks = &drupal_static(__FUNCTION__, array());
if (!empty($blocks[$delta])) {
return $blocks[$delta];
}
$edit = db_query('SELECT * FROM {piecemaker_blocks} WHERE bid = :bid', array(':bid' => $delta))
->fetchAssoc();
$edit['files'] = db_query('SELECT * FROM {piecemaker_blocks_files} WHERE bid = :bid ORDER BY weight ASC', array(':bid' => $delta))
->fetchAllAssoc('weight');
foreach ($edit['files'] as $key => $file) {
$file = (array)$file;
$file['options'] = unserialize($file['data']);
unset($file['data']);
$file['media']['fid'] = $file['fid'];
$edit['files'][$key] = $file;
}
$blocks[$delta] = $edit;
return $blocks[$delta];
}
/**
* Ajax callback for block files
*/
function piecemaker_blocks_file_ajax(&$form, &$form_state) {
return $form['settings']['file'];
}
/**
* Implements hook_form_FORM_ID_alter()
*/
function piecemaker_blocks_form_block_admin_display_form_alter(&$form, &$form_state) {
foreach ($form['blocks'] as $key => $block) {
if ($block['module']['#value'] == 'piecemaker_blocks') {
$form['blocks'][$key]['configure']['#href'] = 'admin/structure/block/piecemaker/edit/' . $block['delta']['#value'];
}
}
}
/**
* Builds the array that will be handed off to the Piecemaker XML file
*
* @return
* A Piecemaker XML array
*/
function piecemaker_blocks_xml_build($delta) {
module_load_include('inc', 'piecemaker_blocks', 'piecemaker_blocks.xml');
return _piecemaker_blocks_xml($delta);
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* @file
* Piecemaker XML related Functions
*/
/**
* Callback for the building of an XML array
*/
function _piecemaker_blocks_xml($delta) {
$block = piecemaker_blocks_block_get($delta);
$items = array();
$profile = (array) piecemaker_profile_load($block['pid']);
$xml['Settings'] = $profile['settings'];
$xml['Transitions'] = $profile['transitions'];
foreach ($block['files'] as $file) {
$type = $file['type'];
$func = "_build_{$type}_array";
if (function_exists($func)) {
$items[] = call_user_func($func, $file);
}
}
$xml['Contents'] = $items;
return $xml;
}
/**
* Builds an Image file type array
*/
function _build_Image_array($file) {
$image = file_load($file['fid']);
$opts = $file['options']['Image'];
$source = image_style_url($opts['style'], $image->uri);
$item['#type'] = $file['type'];
$item['#attributes']['Source'] = $source;
if(!empty($file['options']['Title'])) {
$item['#attributes']['Title'] = $file['options']['Title'];
}
if(!empty($opts['Text']['value'])) {
$item['Text'] = check_markup($opts['Text']['value'], $opts['Text']['format']);
}
if(!empty($opts['Hyperlink'])) {
$url = url($opts['Hyperlink'], array(
'absolute' => TRUE,
'external' => url_is_external($opts['Hyperlink']),
));
$item['Hyperlink'] = array(
'#attributes' => array(
'URL' => $url,
'Target' => empty($opts['Target']) ? '_self' : $opts['Target'],
),
);
}
return $item;
}
/**
* Builds a Video file type array
*/
function _build_Video_array($file) {
$video = file_load($file['fid']);
$opts = $file['options']['Video'];
$item['#type'] = $file['type'];
$item['#attributes']['Source'] = $video->uri;
if(!empty($file['options']['Title'])) {
$item['#attributes']['Title'] = $file['options']['Title'];
}
$item['#attributes']['Width'] = $opts['Width'];
$item['#attributes']['Height'] = $opts['Height'];
$item['#attributes']['Autoplay'] = $opts['Autoplay'];
if(!empty($file['options']['fvimage']['fid'])) {
$image = file_load($file['options']['fvimage']['fid']);
$item['Image'] = array(
'#attributes' => array(
'Source' => $image->uri,
),
);
}
return $item;
}
/**
* Builds a Flash file type array
*/
function _build_Flash_array($file) {
$flash = file_load($file['fid']);
$item['#type'] = $file['type'];
$item['#attributes']['Source'] = $flash->uri;
if(!empty($file['options']['Title'])) {
$item['#attributes']['Title'] = $file['options']['Title'];
}
if(!empty($file['options']['fvimage']['fid'])) {
$image = file_load($file['options']['fvimage']['fid']);
$item['Image'] = array(
'#attributes' => array(
'Source' => $image->uri,
),
);
}
return $item;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,85 @@
<?php
/**
* @file
* Hooks provided by the Piecemaker module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Allows modules to define different handlers for the Piecemaker API
*
* @return
* An Associtive array with ID keys that contain a callback and an access callback
*/
function hook_piecemaker_handler() {
return array(
'example_piecemaker' => array(
'callback' => 'example_piecemaker_settings',
'access' => 'example_piecemaker_access',
),
);
}
/**
* An Example of what a Piecemaker xml array should look like
* Returns the xml array for the piecemaker example
*
* @param $key
* The key from which we would retrieve the settings if this were real
*
* @return
* A structured array from which the piecemaker API will build an XML settings file
*/
function example_piecemaker_settings($key) {
$xml['Settings'] = _piecemaker_default_settings();
$xml['Transitions'] = variable_get('piecemaker_default_transitions', array());
$items[] = array(
'#type' => 'Image',
'#attributes' => array(
'Source' => 'https://mail.google.com/mail/u/0/images/2/5/planets/base/gmail_solid_white_beta.png',
'Title' => 'An Image Node',
),
'Hyperlink' => array(
'#attributes' => array(
'URL' => 'http://google.com',
'Target' => '_parent',
),
),
'Text' => 'Test text. Just to show whats up.'
);
$items[] = array(
'#type' => 'Video',
'#attributes' => array(
'Source' => 'https://mail.google.com/mail/u/0/images/2/5/planets/base/gmail_solid_white_beta.png',
'Title' => 'A Video Node',
'Width' => '960',
'Height' => '360',
'Autoplay' => 'true',
),
'Image' => array(
'#attributes' => array(
'Source' => 'http://google.com',
),
),
);
$items[] = array(
'#type' => 'Flash',
'#attributes' => array(
'Source' => 'https://mail.google.com/mail/u/0/images/2/5/planets/base/gmail_solid_white_beta.png',
'Title' => 'A Flash Node',
),
'Image' => array(
'#attributes' => array(
'Source' => 'http://google.com',
),
),
);
$xml['Contents'] = $items;
return $xml;
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* @file
* Drush integration for the piecemaker module.
*/
/**
* Implements hook_drush_command().
*/
function piecemaker_drush_command() {
$items['piecemaker-download'] = array(
'description' => dt('Downloads the Piecemaker library from https://github.com/arcaneadam/Piecemaker-Drupal.'),
'aliases' => array('pmkdl'),
);
return $items;
}
/**
* Implementation of hook_drush_help().
*/
function piecemaker_drush_help($section) {
switch ($section) {
case 'drush:piecemaker-download':
return dt('Downloads the Piecemaker library from https://github.com/arcaneadam/Piecemaker-Drupal. Places it in the libraries directory. Skips download if library already present. This all happens automatically if you enable piecemaker using drush.');
}
}
/**
* A command callback. Download the Piecemaker library using git.
*/
function drush_piecemaker_download() {
$path = drush_get_context('DRUSH_DRUPAL_ROOT');
$path .= '/'. libraries_get_path('piecemaker');
// If we have the libraries module go ahead and make the path.
if (!is_dir($path)) {
drush_mkdir($path);
}
$version = '7.x-1.x';
$url = "https://github.com/arcaneadam/Piecemaker-Drupal/zipball/{$version}";
$filepath = $path . '/piecemaker.zip';
if (file_exists($path . '/piecemaker.swf')) {
drush_log('Piecemaker already present. No download required.', 'ok');
return;
}
//Download the file
if (!drush_shell_exec('curl -L -o %s ' . $url, $filepath)) {
return drush_set_error('PIECEMAKER_FETCH', dt('Drush was unable to download the Piecemaker library to @path.', array('@path' => $filepath)));
}
// Unzip it the file -- using the "update" option to avoid being prompted
// about overwriting files.
if (!drush_shell_exec("unzip -u {$filepath} -d {$path}")) {
return drush_set_error('PIECEMAKER_UNTAR', dt('Drush was unable to untar the archive @path.', array('@path' => $filepath)));
}
if (!drush_shell_exec("mv {$path}/arcaneadam-Piecemaker-Drupal*/* {$path}")) {
return drush_set_error('PIECEMAKER_MV', dt('Drush was unable to move the files to the appropriate directory'));
}
drush_shell_exec("rm -fR {$path}/arcaneadam-Piecemaker-Drupal*");
drush_log(dt('Piecemaker library has been installed to @path.', array('@path' => $path)), 'success');
}
/**
* Implements drush_MODULE_post_COMMAND().
*/
function drush_piecemaker_post_pm_enable() {
$modules = func_get_args();
if (in_array('piecemaker', $modules)) {
drush_piecemaker_download();
}
}

View File

@@ -0,0 +1,12 @@
name = Piecemaker
package = Piecemaker
description = A general API for utilizing the Piecemaker 3d Flash Rotator
dependencies[] = libraries
core = 7.x
; Information added by drupal.org packaging script on 2011-07-08
version = "7.x-1.0"
core = "7.x"
project = "piecemaker"
datestamp = "1310158319"

View File

@@ -0,0 +1,47 @@
<?php
/**
* @file Install, Update, and Uninstall hooks
*/
/**
* Implements hook_schema
*/
function piecemaker_schema() {
$schema['piecemaker_profiles'] = array(
'description' => 'Piecemaker Profiles',
'fields' => array(
'pid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Profile ID',
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
),
'settings' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
),
'transitions' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
),
'flash_settings' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
),
),
'primary key' => array('pid'),
);
return $schema;
}

View File

@@ -0,0 +1,338 @@
<?php
/**
* @file Module hooks and required files
*/
/**
* Implements hook_menu()
*/
function piecemaker_menu() {
$items['piecemaker/%piecemaker_handler/%/settings.xml'] = array(
'page callback' => 'piecemaker_xml_build',
'page arguments' => array(1),
'load arguments' => array(2),
'access callback' => 'piecemaker_settings_access',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
'file' => 'theme/piecemaker.xml.inc',
);
$items['admin/config/media/piecemaker'] = array(
'title' => 'Piecemaker',
'description' => 'Configure the Piecemaker API Profiles and Settings.',
'page callback' => 'piecemaker_profiles_page',
'access arguments' => array('administer site configuration'),
'file' => 'piecemaker.admin.inc',
);
$items['admin/config/media/piecemaker/profiles'] = array(
'title' => 'Profiles',
'description' => 'Piecemaker API Profiles',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -50,
);
$items['admin/config/media/piecemaker/settings'] = array(
'title' => 'Settings',
'description' => 'Configure the Piecemaker API Settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('piecemaker_settings_page'),
'access arguments' => array('administer site configuration'),
'file' => 'piecemaker.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/config/media/piecemaker/settings/delete_trans/%'] = array(
'title' => 'Settings',
'description' => 'Configure the Piecemaker API Settings.',
'page callback' => 'piecemaker_default_delete_transition',
'page arguments' => array(6),
'access arguments' => array('administer site configuration'),
'file' => 'piecemaker.admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/config/media/piecemaker/profiles/add'] = array(
'title' => 'Add Piecemaker Profile',
'description' => 'Add a Piecemaker API Profile.',
'page callback' => 'drupal_get_form',
'page arguments' => array('piecemaker_profile_form', NULL),
'access arguments' => array('administer site configuration'),
'file' => 'piecemaker.admin.inc',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/config/media/piecemaker/profiles/%piecemaker_profile/edit'] = array(
'title' => 'Edit Piecemaker Profile',
'description' => 'Add a Piecemaker API Profile.',
'page callback' => 'drupal_get_form',
'page arguments' => array('piecemaker_profile_form', 5),
'access arguments' => array('administer site configuration'),
'file' => 'piecemaker.admin.inc',
);
$items['admin/config/media/piecemaker/profiles/%piecemaker_profile/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('piecemaker_profile_delete_confirm', 5),
'access arguments' => array('administer site configuration'),
'file' => 'piecemaker.admin.inc',
);
return $items;
}
/**
* Loads the Piecemaker settings array.
*
* Uses the handlers defined in hook_piecemaker_handler()
*
* @param $handler
* The Handler key as set in hook_piecemaker_handler()
*
* @param $key
* A key to pass to the handler for it to get it's settings
*
* @return
* An associative array containing the needed variables for the settings form
* see @template_preprocess_piecemaker_xml() for the structure of the array
*/
function piecemaker_handler_load($handler, $key) {
$func = piecemaker_handlers($handler);
if (isset($func['callback']) && function_exists($func['callback'])) {
$settings = call_user_func($func['callback'], $key);
$settings['key'] = $key;
$settings['handler'] = array($handler => $func);
return $settings;
}
return FALSE;
}
/**
* Gets the access value for the specific piecemaker settings
*
* @param $handler
* The Handler key as set in hook_piecemaker_handler()
*
* @param $key
* A key to pass to the handler for it to get it's settings
*
* @return
* TRUE or FALSE access value.
*/
function piecemaker_settings_access($handler) {
$func = $handler['handler'];
if (isset($func['access']) && function_exists($func['access'])) {
return call_user_func($func['access'], $key);
}
//default to TRUE
return TRUE;
}
/**
* Gets the piecemaker handlers
*
* @param $handler
* A handler ID to pull from the list of handlers
*/
function piecemaker_handlers($handler = NULL) {
$handlers = &drupal_static(__FUNCTION__);
if (!$handlers) {
$handlers = module_invoke_all('piecemaker_handler');
}
if ($handler && !empty($handlers[$handler])) {
return $handlers[$handler];
}
elseif ($handler && empty($handlers[$handler])) {
return FALSE;
}
return $handlers;
}
/**
* Loads a piecemaker profile
*
* @param $pid
* The profile ID number to load.
*
* @return
* An object containing:
* - pid: The profile ID number
* - title: The profile Title
* - settings: An associative array representing the base settings for this profile
* Returns NULL if no profile with the provided pid is available.
*/
function piecemaker_profile_load($pid) {
$profiles = &drupal_static(__FUNCTION__, array());
if (!empty($profiles[$pid])) {
return $profiles[$pid];
}
$query = db_query('SELECT * FROM {piecemaker_profiles} WHERE pid = :pid', array(':pid' => $pid));
$profile = $query->fetch();
if ($profile) {
$profile->settings = unserialize($profile->settings);
$profile->transitions = !empty($profile->transitions) ? unserialize($profile->transitions) : variable_get('piecemaker_default_transitions', array());
$profile->flash_settings = !empty($profile->flash_settings) ? unserialize($profile->flash_settings) : _piecemaker_default_flash_settings();
}
$profiles[$pid] = $profile;
return $profiles[$pid];
}
/**
* Provides default settings to profiles
*
* @return
* Array of settings values;
*/
function _piecemaker_default_settings() {
$vals = variable_get('piecemaker_default_settings', array());
$settings['ImageWidth'] = isset($vals['ImageWidth']) ? $vals['ImageWidth'] : '900';
$settings['ImageHeight'] = isset($vals['ImageHeight']) ? $vals['ImageHeight'] : '360';
$settings['LoaderColor'] = isset($vals['LoaderColor']) ? $vals['LoaderColor'] : '0x333333';
$settings['InnerSideColor'] = isset($vals['InnerSideColor']) ? $vals['InnerSideColor'] : '0x222222';
$settings['SideShadowAlpha'] = isset($vals['SideShadowAlpha']) ? $vals['SideShadowAlpha'] : '0.8';
$settings['DropShadowAlpha'] = isset($vals['DropShadowAlpha']) ? $vals['DropShadowAlpha'] : '0.7';
$settings['DropShadowDistance'] = isset($vals['DropShadowDistance']) ? $vals['DropShadowDistance'] : '25';
$settings['DropShadowScale'] = isset($vals['DropShadowScale']) ? $vals['DropShadowScale'] : '0.95';
$settings['DropShadowBlurX'] = isset($vals['DropShadowBlurX']) ? $vals['DropShadowBlurX'] : '40';
$settings['DropShadowBlurY'] = isset($vals['DropShadowBlurY']) ? $vals['DropShadowBlurY'] : '4';
$settings['MenuDistanceX'] = isset($vals['MenuDistanceX']) ? $vals['MenuDistanceX'] : '20';
$settings['MenuDistanceY'] = isset($vals['MenuDistanceY']) ? $vals['MenuDistanceY'] : '50';
$settings['MenuColor1'] = isset($vals['MenuColor1']) ? $vals['MenuColor1'] : '0x999999';
$settings['MenuColor2'] = isset($vals['MenuColor2']) ? $vals['MenuColor2'] : '0x333333';
$settings['MenuColor3'] = isset($vals['MenuColor3']) ? $vals['MenuColor3'] : '0xFFFFFF';
$settings['ControlSize'] = isset($vals['ControlSize']) ? $vals['ControlSize'] : '100';
$settings['ControlDistance'] = isset($vals['ControlDistance']) ? $vals['ControlDistance'] : '20';
$settings['ControlColor1'] = isset($vals['ControlColor1']) ? $vals['ControlColor1'] : '0x222222';
$settings['ControlColor2'] = isset($vals['ControlColor2']) ? $vals['ControlColor2'] : '0xFFFFFF';
$settings['ControlAlpha'] = isset($vals['ControlAlpha']) ? $vals['ControlAlpha'] : '0.8';
$settings['ControlAlphaOver'] = isset($vals['ControlAlphaOver']) ? $vals['ControlAlphaOver'] : '0.95';
$settings['ControlsX'] = isset($vals['ControlsX']) ? $vals['ControlsX'] : '450';
$settings['ControlsY'] = isset($vals['ControlsY']) ? $vals['ControlsY'] : '280';
$settings['ControlsAlign'] = isset($vals['ControlsAlign']) ? $vals['ControlsAlign'] : 'center';
$settings['TooltipHeight'] = isset($vals['TooltipHeight']) ? $vals['TooltipHeight'] : '31';
$settings['TooltipColor'] = isset($vals['TooltipColor']) ? $vals['TooltipColor'] : '0x222222';
$settings['TooltipTextY'] = isset($vals['TooltipTextY']) ? $vals['TooltipTextY'] : '5';
$settings['TooltipTextStyle'] = isset($vals['TooltipTextStyle']) ? $vals['TooltipTextStyle'] : 'P-Italic';
$settings['TooltipTextColor'] = isset($vals['TooltipTextColor']) ? $vals['TooltipTextColor'] : '0xFFFFFF';
$settings['TooltipMarginLeft'] = isset($vals['TooltipMarginLeft']) ? $vals['TooltipMarginLeft'] : '5';
$settings['TooltipMarginRight'] = isset($vals['TooltipMarginRight']) ? $vals['TooltipMarginRight'] : '7';
$settings['TooltipTextSharpness'] = isset($vals['TooltipTextSharpness']) ? $vals['TooltipTextSharpness'] : '50';
$settings['TooltipTextThickness'] = isset($vals['TooltipTextThickness']) ? $vals['TooltipTextThickness'] : '-100';
$settings['InfoWidth'] = isset($vals['InfoWidth']) ? $vals['InfoWidth'] : '400';
$settings['InfoBackground'] = isset($vals['InfoBackground']) ? $vals['InfoBackground'] : '0xFFFFFF';
$settings['InfoBackgroundAlpha'] = isset($vals['InfoBackgroundAlpha']) ? $vals['InfoBackgroundAlpha'] : '0.95';
$settings['InfoMargin'] = isset($vals['InfoMargin']) ? $vals['InfoMargin'] : '15';
$settings['InfoSharpness'] = isset($vals['InfoSharpness']) ? $vals['InfoSharpness'] : '0';
$settings['InfoThickness'] = isset($vals['InfoThickness']) ? $vals['InfoThickness'] : '0';
$settings['Autoplay'] = isset($vals['Autoplay']) ? $vals['Autoplay'] : '10';
$settings['FieldOfView'] = isset($vals['FieldOfView']) ? $vals['FieldOfView'] : '45';
return $settings;
}
/**
* Provides the default flash settings to profiles
*/
function _piecemaker_default_flash_settings() {
$vals = variable_get('piecemaker_default_flash_settings', array('params' => array()));
$pm_path = libraries_get_path('piecemaker');
$settings['width'] = isset($vals['width']) ? $vals['width'] : '900';
$settings['height'] = isset($vals['height']) ? $vals['height'] : '600';
$settings['flashvars']['cssSource'] = isset($vals['flashvars']['cssSource']) ? $vals['flashvars']['cssSource'] : $pm_path . '/piecemaker.css';
$settings['params']['play'] = isset($vals['params']['play']) ? $vals['params']['play'] : 'true';
$settings['params']['menu'] = isset($vals['params']['menu']) ? $vals['params']['menu'] : 'false';
$settings['params']['scale'] = isset($vals['params']['scale']) ? $vals['params']['scale'] : 'showall';
$settings['params']['wmode'] = isset($vals['params']['wmode']) ? $vals['params']['wmode'] : 'transparent';
$settings['params']['allowfullscreen'] = isset($vals['params']['allowfullscreen']) ? $vals['params']['allowfullscreen'] : 'true';
$settings['params']['allowscriptaccess'] = isset($vals['params']['allowscriptaccess']) ? $vals['params']['allowscriptaccess'] : 'always';
$settings['params']['allownetowrking'] = isset($vals['params']['allownetworking']) ? $vals['params']['allownetworking'] : 'true';
$settings['params'] = array_merge($settings['params'], $vals['params']);
return $settings;
}
/**
* Implements hook_theme()
*/
function piecemaker_theme() {
$path = drupal_get_path('module', 'piecemaker');
return array(
'piecemaker' => array(
'variables' => array('handler' => NULL, 'key' => NULL, 'profile' => array(), 'alternate_callback' => NULL),
'path' => $path . '/theme',
'file' => 'theme.inc',
),
'piecemaker_transition_form' => array(
'render element' => 'form',
'path' => $path . '/theme',
'file' => 'theme.inc',
),
'piecemaker_profile_params' => array(
'render element' => 'form',
'path' => $path . '/theme',
'file' => 'theme.inc',
),
'piecemaker_xml' => array(
'template' => 'piecemaker-xml',
'path' => $path . '/theme',
'file' => 'piecemaker.xml.inc',
'variables' => array('Settings' => array(), 'Transitions' => array(), 'Contents' => array(), 'handler' => array(), 'key' => NULL),
),
'piecemaker_xml_node' => array(
'path' => $path . '/theme',
'file' => 'piecemaker.xml.inc',
'variables' => array('item' => array()),
),
'piecemaker_xml_node_Image' => array(
'template' => 'piecemaker-xml-image',
'path' => $path . '/theme',
'file' => 'theme.inc',
'variables' => array('item' => array()),
),
'piecemaker_xml_node_Video' => array(
'template' => 'piecemaker-xml-video',
'path' => $path . '/theme',
'file' => 'theme.inc',
'variables' => array('item' => array()),
),
'piecemaker_xml_node_Flash' => array(
'template' => 'piecemaker-xml-flash',
'path' => $path . '/theme',
'file' => 'theme.inc',
'variables' => array('item' => array()),
),
);
}
/**
* Ajax callback for admin form
*/
function piecemaker_add_transition_ajax($form, $form_state) {
$key = $form_state['#transition_element'];
return $form[$key];
}
/**
* Ajax callback for admin form
*/
function piecemaker_add_flash_params($form, $form_state) {
return $form['flash_settings']['params'];
}
/**
* Utility function that allows other modules to get a list of profiles keyed on the pid
*
* @return
* An array of profiles keyed on the pid
*/
function piecemaker_profile_options() {
$profiles = &drupal_static(__FUNCTION__);
if (!$profiles) {
$profiles = db_query('SELECT title, pid FROM {piecemaker_profiles}')
->fetchAllKeyed(1,0);
}
return $profiles;
}
/**
* Implements hook_page_alter()
*/
function piecemaker_page_alter(&$page) {
//We add all our piecemaker settings here right before the page renders to ensure that there are no
//array merging errors
$settings = drupal_static('theme_piecemaker_settings');
if (is_array($settings)) {
drupal_add_js($settings, 'setting');
}
}

View File

@@ -0,0 +1,14 @@
<?php
/**
* @file
* Outputs the Flash XML node for piecemaker xml files
*
* @variables
* $item: An associative array. @see template_preprocess_piecemaker_xml for details
*/
?>
<Flash <?php print drupal_attributes($item['#attributes']); ?>>
<?php if (!empty($item['Image']['#attributes'])):?>
<Image <?php print drupal_attributes($item['Image']['#attributes']);?>/>
<?php endif;?>
</Flash>

View File

@@ -0,0 +1,17 @@
<?php
/**
* @file
* Outputs the Image XML node for piecemaker xml files
*
* @variables
* $item: An associative array. @see template_preprocess_piecemaker_xml for details
*/
?>
<Image <?php print drupal_attributes($item['#attributes']); ?>>
<?php if (!empty($item['Text'])):?>
<Text><?php print $item['Text']; ?></Text>
<?php endif;?>
<?php if (!empty($item['Hyperlink']['#attributes'])):?>
<Hyperlink <?php print drupal_attributes($item['Hyperlink']['#attributes']);?>/>
<?php endif;?>
</Image>

View File

@@ -0,0 +1,14 @@
<?php
/**
* @file
* Outputs the Flash XML node for piecemaker xml files
*
* @variables
* $item: An associative array. @see template_preprocess_piecemaker_xml for details
*/
?>
<Video <?php print drupal_attributes($item['#attributes']); ?>>
<?php if (!empty($item['Image']['#attributes'])):?>
<Image <?php print drupal_attributes($item['Image']['#attributes']);?>/>
<?php endif;?>
</Video>

View File

@@ -0,0 +1,14 @@
<?php
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
?>
<Piecemaker>
<Contents>
<?php print implode("\n",$ContentNodes); ?>
</Contents>
<Settings <?php print drupal_attributes($Settings); ?>></Settings>
<Transitions>
<?php foreach($Transitions as $transition):?>
<Transition <?php print drupal_attributes($transition); ?>></Transition>
<?php endforeach;?>
</Transitions>
</Piecemaker>

View File

@@ -0,0 +1,52 @@
<?php
/**
* @file
* Function related to the Building of the Piecemaker XML file
*/
/**
* Builds a Piecemaker XML file
*
*/
function piecemaker_xml_build($settings) {
drupal_add_http_header('Content-Type', 'text/xml; charset=utf-8');
print theme('piecemaker_xml', $settings);
exit();
}
/**
* Preprocess Function for the Settings XML file
* @param $vars
* An associative array of the needed items to generate an XML file
* - 'Settings': The settings array of to be used. Most likely this comes from a piecemaker profile
* - 'Transitions': The transitions array to be used. Once again this is most likely comming from a profile
* - 'Contents': An item array containing the following keys
* - '#type': Either 'Image', 'Video', or 'Flash'
* - '#attributes': An array of attributes to add to the main node
* - 'Source': The Source of the file. This should be generated using $base_url to ensure it points correctly. REQUIRED for all file types.
* - 'Title': The title of the file. Will be shown in the tooltip on the menu. Avaialable to all file types.
* - 'Width': Only used in Video files. The width of the video file.
* - 'Height': Only used in Video files. The height of the video file.
* - 'Autoplay': Only used in Video files. Autoplay defines whether or not the video will start playing as soon as its ready.
* - 'Text': Used in Image nodes. The Text node can hold a description text, which can be formatted with simple HTML tags.
* Which HTML tags are supported, is determined by the piecemaker.css file. Per default you can use <h1>, <p>, <p-italic>, <a>.
* But you can add and specify as many tags as you want, for example different headline types. If you want to use different fonts,
* you will have to make sure that you embed these fonts in the Flash file. If you dont add a Text node, no info text appears.
* - 'Hyperlink': An array that contains an #attributes key which holds the attributes URL and Target.
* - 'Image': The Flash and Video nodes must have a child array Image, which will also have a Source #attribute key. This will specify the path to a preview image to be loaded before the SWF/Video file is shown.
* This preview image might show the first image of the SWF/Video file though, which would cause a smooth transition from the image to the actual SWF/Video.
* Please note that this image will still be shown left and right of the video, in case that the video is not as wide as the image.
*/
function template_preprocess_piecemaker_xml(&$vars) {
foreach($vars['Contents'] as $item) {
$Contents[] = theme('piecemaker_xml_node', array('item' => $item));
}
$vars['ContentNodes'] = $Contents;
}
/**
* Generates the individual nodes for a piecemaker XML file.
*/
function theme_piecemaker_xml_node(&$vars) {
$hook = 'piecemaker_xml_node_' . $vars['item']['#type'];
return theme($hook, $vars);
}

View File

@@ -0,0 +1,147 @@
<?php
/**
* @file
* Contains various theme functions for Piecemaker API
*/
/**
* Themes the actuall Piecemaker element
*
* @param $vars
* An array that contains the handler, key, profile array, and alternate content callback function
*/
function theme_piecemaker($vars) {
$settings = &drupal_static('theme_piecemaker_settings');
$ids = &drupal_static(__FUNCTION__, array());
$handler = $vars['handler'];
$key = $vars['key'];
$profile = $vars['profile'];
$alternate_callback = $vars['alternate_callback'];
if (is_object($profile)) {
//Cast the profile to an array to make it easier to use
$profile = (array) $profile;
}
$id = 'piecemaker-' . $handler . '-' . $key;
$i = 0;
while (in_array($id, $ids)) {
//Ensure we have a unique html ID to use.
$id .= '-' . $i;
$i++;
}
//Store this id
$ids[] = $id;
$pm_path = libraries_get_path('piecemaker');
$path = drupal_get_path('module', 'piecemaker');
//Add The JS we need
drupal_add_js($pm_path . '/swfobject/swfobject.js');
drupal_add_js($path . '/js/Piecemaker.js', JS_THEME);
$settings['Piecemaker_URI'] = base_path() . $pm_path;
$settings['Piecemaker'][$id] = array(
'id' => $id,
'flashvars' => array(
'xmlSource' => base_path() . "piecemaker/{$handler}/{$key}/settings.xml",
'cssSource' => base_path() . $profile['flash_settings']['flashvars']['cssSource'],
),
'width' => $profile['flash_settings']['width'],
'height' => $profile['flash_settings']['height'],
);
$settings['Piecemaker'][$id]['params'] = $profile['flash_settings']['params'];
$alternate = '<p>You do not have flash enabled</p>';
if (function_exists($alternate_callback)) {
$alternate = call_user_func_array($alternate_callback, $vars);
}
$out = "<div id=\"{$id}\" class=\"piecemaker piecemaker-{$handler} piecemaker-{$handler}-{$key}\">
{$alternate}
</div>";
return $out;
}
/**
* Themes the tranistion add/delete protion of the proile form
*/
function theme_piecemaker_transition_form($vars) {
$form = $vars['form'];
$tvars['header'] = array(
t('Effect'),
t('Weight'),
t('Pieces'),
t('Time'),
t('Delay'),
t('Depth Offset'),
t('Cube Distance'),
t('Add/Delete')
);
foreach(element_children($form) as $key) {
$row = array();
if ($key === 'add') {
//We need to create a item list that will be appended to the bottom of the form
//since the descriptions are getting too big for the table and break the layout
$head = $tvars['header'];
$items[] = array_shift($head) . ': ' . $form[$key]['Transition']['#description'];
unset($form[$key]['Transition']['#description']);
array_shift($head); //To get rid of the weight column
$items[] = array_shift($head) . ': ' . $form[$key]['Pieces']['#description'];
unset($form[$key]['Pieces']['#description']);
$items[] = array_shift($head) . ': ' . $form[$key]['Time']['#description'];
unset($form[$key]['Time']['#description']);
$items[] = array_shift($head) . ': ' . $form[$key]['Delay']['#description'];
unset($form[$key]['Delay']['#description']);
$items[] = array_shift($head) . ': ' . $form[$key]['DepthOffset']['#description'];
unset($form[$key]['DepthOffset']['#description']);
$items[] = array_shift($head) . ': ' . $form[$key]['CubeDistance']['#description'];
unset($form[$key]['CubeDistance']['#description']);
}
$row[] = drupal_render($form[$key]['Transition']);
$row[] = drupal_render($form[$key]['weight']);
$row[] = drupal_render($form[$key]['Pieces']);
$row[] = drupal_render($form[$key]['Time']);
$row[] = drupal_render($form[$key]['Delay']);
$row[] = drupal_render($form[$key]['DepthOffset']);
$row[] = drupal_render($form[$key]['CubeDistance']);
$row[] = drupal_render($form[$key]['action']);
$tvars['rows'][] = array(
'data' => $row,
'class' => array('draggable'),
);
}
$tvars['attributes'] = array(
'id' => 'piecemaker-transitions',
'class' => array('no-sticky'),
);
//Sticky headers don't work with draggable tables.
$tvars['sticky'] = FALSE;
$fieldset = array(
'#type' => 'fieldset',
'#title' => 'Field Descriptions',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$fieldset['list']['#markup'] = theme('item_list', array('items' => $items));
drupal_add_tabledrag('piecemaker-transitions', 'order', 'sibling', 'trans-weight');
return theme('table', $tvars) . drupal_render($fieldset);
}
/**
* Themes the flash params protion of the proile form
*/
function theme_piecemaker_profile_params($vars) {
$form = $vars['form'];
$add = drupal_render($form['add']);
foreach(element_children($form) as $key) {
$row = array();
$row[] = drupal_render($form[$key]['key']);
$row[] = drupal_render($form[$key]['value']);
$tvars['rows'][] = $row;
}
$tvars['header'] = array(
t('Key'),
t('Value'),
);
$tvars['attributes'] = array(
'id' => 'piecemaker-params',
);
return theme('table', $tvars) . $add;
}