View source
<?php
require_once 'scald.constants.inc';
function scald_admin_dashboard() {
$scald_providers = variable_get('scald_providers', array());
$content = t('
<h3>Scald Providers</h3>
<p>The following Scald Providers are registered with Scald Core. To force a Provider to renew its registration (this is useful if a Provider conditionally provides something such as a Transcoder based on whether or not a module is availble and you have just enabled new modules) click the <em>re-register</em> link next to the Provider\'s name.</p>
<ul>
');
foreach ($scald_providers as $provider) {
$content .= '<li>' . $provider . '.module [' . l('re-register', 'admin/content/scald/register/' . $provider) . ']</li>';
}
$content .= '</ul>';
return $content;
}
function scald_admin_provider_reregister($provider) {
if (_scald_register_provider($provider, module_invoke($provider, 'scald_provider'), TRUE)) {
drupal_set_message(t('Successfuly re-registered Scald Provider %provider', array(
'%provider' => $provider . '.module',
)));
}
else {
drupal_set_message(t('Re-registering Scald Provider %provider failed.', array(
'%provider' => $provider . '.module',
)), 'error');
}
scald_config_rebuild();
drupal_goto('admin/content/scald');
}
function scald_admin_types() {
$scald_config = variable_get('scald_config', 0);
$content = t('
<h3>Scald Unified Types</h3>
<br>
<p>Scald Unified Types are a way of dealing with various different media *formats* in a uniform manner. For instance, from the average user\'s perspective, a JPEG and a PNG are pretty much the same thing. Both could be classified as the Scald Unified Type "Image".</p>
<p>When users interact with Atoms, they will often see the title of the Type of Atom. That title can be customized below. Be sure to specify the title in the singular, not plural, form.</p>
');
return $content . drupal_get_form('scald_admin_types_form');
}
function scald_admin_types_form() {
$form = array();
$types_results = db_query("\n SELECT\n *\n FROM\n {scald_types}\n ");
while ($type_raw = db_fetch_array($types_results)) {
$form[$type_raw['type']] = array(
'#type' => 'fieldset',
'#title' => check_plain($type_raw['title']),
'#description' => $type_raw['description'] . '<br>' . t('Provided by <code>@module.module</code>', array(
'@module' => $type_raw['provider'],
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form[$type_raw['type']]['type_' . $type_raw['type'] . '_title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $type_raw['title'],
'#size' => 40,
'#maxlength' => 255,
'#required' => TRUE,
);
$scald_config = variable_get('scald_config', 0);
$scald_atom_defaults = variable_get('scald_atom_defaults', 0);
$form[$type_raw['type']]['defaults'] = array(
'#type' => 'fieldset',
'#title' => t('Defaults'),
'#description' => t('Every Atom must have certain data associated with it. If an Atom Provider fails to supply that data, these defaults are used. If nothing is specified here, Scald Core will supply generic defaults.'),
'#collapsible' => FALSE,
);
$form[$type_raw['type']]['defaults']['type_' . $type_raw['type'] . '_thumb'] = array(
'#type' => 'textfield',
'#title' => t('Default Thumbnail Image'),
'#description' => t('Specify a path relative to the Drupal install directory. This image file will be automatically resized and transcoded as appropriate when generating the actual thumbnail image.'),
'#default_value' => $scald_atom_defaults->thumbnail_source[$type_raw['type']],
'#size' => 40,
'#maxlength' => 255,
'#required' => TRUE,
);
$form[$type_raw['type']]['defaults']['type_' . $type_raw['type'] . '_descr'] = array(
'#type' => 'textfield',
'#title' => t('Default Description'),
'#description' => t('Empty strings are permitted.'),
'#default_value' => $scald_atom_defaults->description[$type_raw['type']],
'#size' => 40,
'#maxlength' => 255,
'#required' => TRUE,
);
$form[$type_raw['type']]['defaults']['type_' . $type_raw['type'] . '_actin'] = array(
'#type' => 'textfield',
'#title' => t('Default Actions bitstring'),
'#description' => t('Should be an integer. Note that the numbering on the Actions Admin page does not correspond to bit order.'),
'#default_value' => $scald_atom_defaults->actions[$type_raw['type']],
'#size' => 10,
'#maxlength' => 24,
'#required' => TRUE,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function scald_admin_types_form_submit($form, &$form_state) {
$scald_atom_defaults = variable_get('scald_atom_defaults', 0);
foreach ($form_state['values'] as $key => $value) {
if (substr($key, 0, 5) == 'type_') {
$type = substr($key, 5, -6);
switch (substr($key, -6)) {
case '_title':
db_query("\n UPDATE\n {scald_types}\n SET\n title = '%s'\n WHERE\n type = '%s'\n ", $value, $type);
break;
case '_thumb':
$scald_atom_defaults->thumbnail_source[$type] = $value;
break;
case '_descr':
$scald_atom_defaults->description[$type] = $value;
break;
case '_actin':
$scald_atom_defaults->actions[$type] = (int) $value;
break;
}
}
}
variable_set('scald_atom_defaults', $scald_atom_defaults);
scald_config_rebuild('types');
}
function scald_admin_atoms() {
$content = t('
<h3>Scald Atoms</h3>
<h4>Currently, there are ' . db_result(db_query("SELECT COUNT(*) FROM {scald_atoms}")) . ' Atoms registered with Scald Core.</h4>
<p>Enable the Views module to get an handy paginated table with filters which will allow you to browse your atoms</p>
');
$scald_config = variable_get('scald_config', 0);
$atoms_results = db_query("\n SELECT\n *\n FROM\n {scald_atom_providers}\n ORDER BY\n type\n ");
$content .= '<ol>';
$first = TRUE;
$current = '';
while ($atom_raw = db_fetch_array($atoms_results)) {
if ($current != $atom_raw['type']) {
$current = $atom_raw['type'];
if (!$first) {
$content .= '</ul></li>';
}
else {
$first = FALSE;
}
$content .= '
<li>
<strong>' . check_plain($scald_config->types[$atom_raw['type']]['title']) . '</strong> Atoms are based on:
<ul>
';
}
$content .= '<li>' . check_plain($atom_raw['base_description']) . ' (Provided by <code>' . $atom_raw['provider'] . '.module</code>)</li>';
}
$content .= '</ul></li></ol>';
return $content;
}
function scald_admin_contexts() {
$scald_config = variable_get('scald_config', 0);
$content = t('
<h3>Scald Rendering Contexts</h3>
<br>
<p>Scald Rendering Contexts are something like themes for Scald Atoms. Any Atom can be rendered in any Context and the Context determines what that rendering looks like and what language it is in.</p>
<p>If a Context is "parseable", that means that its output is wrapped in HTML comments (currently this feature only works reliably for Contexts which have a render language of XHTML) which make it possible for Scald Core to uniquely identify the Atom based on the rendering. For instance, if a WYSIWYG editor is being used in some text areas and Scald Atoms should be included in the WYSIWYG preview of the text, a Context can be chosen and specified as parseable. That ensures that when the textarea is submitted, Scald Core will be able to determine which Atoms are present in the textarea, convert the rendered versions to Scald Atom Shorthand and ensure proper parsing by the Scald Atom Shorthand Input Filter.</p>
');
return $content . drupal_get_form('scald_admin_contexts_form');
}
function scald_admin_contexts_form() {
$form = array();
$scald_config = variable_get('scald_config', 0);
$contexts_results = db_query("\n SELECT\n c.*\n FROM\n {scald_contexts} c\n ORDER BY\n c.title\n ");
while ($context_raw = db_fetch_array($contexts_results)) {
$context = $context_raw['context'];
$form[$context] = array(
'#type' => 'fieldset',
'#title' => $context_raw['title'],
'#description' => $context_raw['description'] . '<br>' . t('Provided by <code>@module.module</code>.', array(
'@module' => $context_raw['provider'],
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form[$context][$context . '_pars'] = array(
'#type' => 'checkbox',
'#title' => t('Make parseable.'),
'#default_value' => (bool) $context_raw['parseable'],
);
$form[$context]['transcoders'] = array(
'#type' => 'fieldset',
'#title' => t('Transcoders for %context by Atom Type', array(
'%context' => $context,
)),
'#collapsible' => FALSE,
);
foreach ($scald_config->types as $type => $details) {
$transcoders = array();
$transcoders['@none'] = t('None');
$transcoders['passthrough@passthrough'] = t('Passthrough');
$transcoder_results = db_query("\n SELECT\n t.transcoder AS transcoder,\n t.title AS title,\n tf.file_format AS file_format\n FROM\n {scald_transcoders} t\n LEFT JOIN\n {scald_transcoder_formats} tf\n ON tf.transcoder = t.transcoder\n WHERE\n tf.file_format IN (SELECT file_format FROM {scald_context_type_formats} WHERE context='%s')\n ", $context);
while ($transcoder_raw = db_fetch_array($transcoder_results)) {
$transcoders[$transcoder_raw['transcoder'] . '@' . $transcoder_raw['file_format']] = $transcoder_raw['title'];
}
$form[$context]['transcoders'][$context . '@' . $type . '_type'] = array(
'#type' => 'select',
'#title' => $scald_config->types[$type]['title'],
'#default_value' => !empty($scald_config->contexts[$context]['type_format']) && !empty($scald_config->contexts[$context]['type_format'][$type]) ? $scald_config->contexts[$context]['type_format'][$type]['transcoder'] . '@' . $scald_config->contexts[$context]['type_format'][$type]['file_format'] : '@none',
'#options' => $transcoders,
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function scald_admin_contexts_form_submit($form, &$form_state) {
foreach ($form_state['values'] as $key => $value) {
switch (substr($key, -5)) {
case '_pars':
db_query("\n UPDATE\n {scald_contexts}\n SET\n parseable = %d\n WHERE\n context = '%s'\n ", $value, substr($key, 0, -5));
break;
case '_type':
list($context, $type) = split('@', substr($key, 0, -5));
list($transcoder, $file_format) = split('@', $value);
if ($value == '@none') {
db_query("DELETE FROM {scald_context_type_transcoder} WHERE context = '%s' AND type = '%s'", $context, $type);
}
else {
db_query("\n INSERT INTO\n {scald_context_type_transcoder}\n SET\n context = '%s',\n type = '%s',\n file_format = '%s',\n transcoder = '%s'\n ON DUPLICATE KEY\n UPDATE\n file_format = '%s',\n transcoder = '%s'\n ", $context, $type, $file_format, $transcoder, $file_format, $transcoder);
}
break;
}
}
$config_old = variable_get('scald_config', 0);
$old = $config_old->contexts;
scald_config_rebuild('contexts');
$config_new = variable_get('scald_config', 0);
$new = $config_new->contexts;
$changed = FALSE;
foreach ($new as $name => $context) {
if ($new[$name]['parseable'] != $old[$name]['parseable']) {
$changed = TRUE;
}
foreach ($new[$name]['type_format'] as $type => $format) {
if ($new[$name]['type_format'][$type]['transcoder'] != $old[$name]['type_format'][$type]['transcoder']) {
$changed = TRUE;
}
}
}
if ($changed) {
cache_clear_all('*', 'cache_scald', TRUE);
}
}
function scald_admin_transcoders() {
$content = t('
<h3>Scald Transcoders</h3>
<br>
<p>Scald Transcoders take the files associated with Atoms of a particular Type and transcode them into a file format which is appropriate for output. Any configuration for the Transcoders should be completed on the settings page for the Providing module.</p>
<ol>
<li>
<strong>Passthrough</strong>
<ul>
<li><em>The Passthrough Transcoder simply makes the source file available to the rendering stack in an unmodified form.</em></li>
<li>Provided by <code>scald.module</code></li>
</ul>
</li>
');
$transcoders_results = db_query("\n SELECT\n *\n FROM\n {scald_transcoders}\n ");
while ($transcoder_raw = db_fetch_array($transcoders_results)) {
$content .= '
<li>
<strong>' . $transcoder_raw['title'] . '</strong>
<ul>
<li><em>' . $transcoder_raw['description'] . '</em></li>
<li>Provided by <code>' . $transcoder_raw['provider'] . '.module</code></li>
</ul>
</li>
';
}
$content .= '</ol>';
return $content;
}
function scald_admin_relationships() {
$content = t('
<h3>Scald Atom Relationships</h3>
<p>Scald Atom Relationships define a way in which two Atoms can be related. What is done with this information is dependant on the nature of the relationship.</p>
<ol>
');
$relationships_results = db_query("\n SELECT\n *\n FROM\n {scald_relationships}\n ");
while ($relationship_raw = db_fetch_array($relationships_results)) {
$content .= '
<li>
<strong>A ' . $relationship_raw['title'] . ' B / B ' . $relationship_raw['title_reverse'] . ' A</strong>
<ul>
<li><em>' . $relationship_raw['description'] . '</em></li>
<li>Provided by <code>' . $relationship_raw['provider'] . '.module</code></li>
</ul>
</li>
';
}
$content .= '</ol>';
return $content;
}
function scald_admin_actions() {
$content_first = t('
<h3>Scald Actions</h3>
<p>Scald Actions are akin to Drupal Permissions. Each is something which can be done <em>to</em> or <em>with</em> an Atom. They are assigned to Drupal user roles. Only roles which have the "use scald" permission can have Actions assigned to them.</p>
');
$content = t('
<ol>
<li>
<strong>Admin Mode</strong>
<ul>
<li><em>The Admin Mode Action is not an Action but a characteristic of a Role\'s permitted actions. If it is given to a Role, that Role\'s Actions will be permitted for <strong>all</strong> Atoms, even if the Actions settings for an Atom indicate that those Actions are not permitted. Permitting this pseudo-action does <strong>not</strong> grant the Role the ability to administer Scald. That must be granted through the Drupal User Permissions interface (permission \'adminster scald\'). Assign this pseudo-action with caution as it can lead to licensing violations.</em></li>
<li>Provided by <code>scald.module</code></li>
</ul>
</li>
<li>
<strong>Fetch</strong>
<ul>
<li><em>The Fetch Action is the an internal Action. Without this Action permitted, a Role cannot effectively use Scald. Without this Action permitted for an Atom, that Atom cannot even be loaded, effectively masking it from everyone who does not have Admin Mode permitted.</em></li>
<li>Provided by <code>scald.module</code></li>
</ul>
</li>
');
$actions_results = db_query("\n SELECT\n provider,\n title,\n description\n FROM\n {scald_actions}\n ");
while ($action_raw = db_fetch_array($actions_results)) {
$content .= '
<li>
<strong>' . $action_raw['title'] . '</strong>
<ul>
<li><em>' . $action_raw['description'] . '</em></li>
<li>Provided by <code>' . $action_raw['provider'] . '.module</code></li>
</ul>
</li>
';
}
$content .= '</ol>';
return $content_first . drupal_get_form('scald_admin_actions_form') . $content;
}
function scald_admin_actions_form() {
$scald_config = variable_get('scald_config', 0);
$scald_actions_publisher = variable_get('scald_actions_publisher', 0);
$action_options = array();
foreach ($scald_config->actions as $slug => $details) {
$action_options[$slug] = $details['title'];
}
$form = array();
$form['@publisher_set'] = array(
'#type' => 'fieldset',
'#title' => t('Atom Publisher'),
'#description' => t('The Atom Publisher is not a role but is the User who initially registered a given Scald Atom. Admin Mode is recommended for the Publisher\'s Permitted Actions.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$current_actions = array();
foreach ($scald_config->actions as $slug => $details) {
if ($scald_actions_publisher & $details['mask']) {
$current_actions[] = $slug;
}
}
$form['@publisher_set']['@publisher_role'] = array(
'#type' => 'checkboxes',
'#title' => t('Permitted Actions'),
'#default_value' => $current_actions,
'#options' => $action_options,
);
$roles_results = db_query("\n SELECT\n p.rid,\n p.perm,\n r.name,\n a.actions\n FROM\n {permission} p\n LEFT JOIN\n {role} r\n ON\n r.rid = p.rid\n LEFT JOIN\n {scald_role_actions} a\n ON\n a.rid = p.rid\n ");
while ($role_raw = db_fetch_array($roles_results)) {
$perms = explode(', ', $role_raw['perm']);
if (in_array('use scald', $perms)) {
$form[$role_raw['rid'] . '_set'] = array(
'#type' => 'fieldset',
'#title' => $role_raw['name'],
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$current_actions = array();
foreach ($scald_config->actions as $slug => $details) {
if ($role_raw['actions'] & $details['mask']) {
$current_actions[] = $slug;
}
}
$form[$role_raw['rid'] . '_set'][$role_raw['rid'] . '_role'] = array(
'#type' => 'checkboxes',
'#title' => t('Permitted Actions'),
'#default_value' => $current_actions,
'#options' => $action_options,
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function scald_admin_actions_form_submit($form, &$form_state) {
$scald_config = variable_get('scald_config', 0);
$actions_results = db_query("SELECT rid, actions FROM {scald_role_actions}");
$roles = array();
while ($actions_raw = db_fetch_array($actions_results)) {
$roles[$actions_raw['rid']] = $actions_raw['actions'];
}
$updated = array();
foreach ($form_state['values'] as $role => $actions) {
if (substr($role, -5) == '_role') {
$role = substr($role, 0, -5);
$bitstring = 0;
foreach ($actions as $slug => $set) {
if (!empty($set)) {
$bitstring = $bitstring | $scald_config->actions[$slug]['mask'];
}
}
if ($role == '@publisher') {
variable_set('scald_actions_publisher', $bitstring);
}
else {
if ($bitstring != $roles[$role]) {
db_query("\n INSERT INTO\n {scald_role_actions}\n SET\n actions = %d,\n rid = %d\n ON DUPLICATE KEY\n UPDATE\n actions = %d\n ", $bitstring, $role, $bitstring);
$updated[] = (int) $role;
}
}
}
}
if (!empty($updated)) {
batch_set(array(
'title' => t('Updating User Actions bitstrings.'),
'operations' => array(
array(
'scald_admin_actions_batch',
array(
$updated,
),
),
),
'progress_message' => '',
'file' => drupal_get_path('module', 'scald') . '/scald.admin.inc',
));
batch_process('admin/content/scald/actions');
}
}
function scald_admin_actions_batch($roles, &$context) {
if (!isset($context['sandbox']['last_uid'])) {
$context['sandbox']['all_users'] = in_array(DRUPAL_AUTHENTICATED_RID, $roles);
$context['sandbox']['progress'] = 0;
$context['sandbox']['last_uid'] = 0;
$context['sandbox']['total'] = db_result(db_query("\n SELECT\n COUNT(DISTINCT uid)\n FROM " . ($context['sandbox']['all_users'] ? '{users}' : '{users_roles}') . " WHERE " . ($context['sandbox']['all_users'] ? "" : "rid IN (" . implode(', ', $roles) . ") AND ") . "uid > %d\n ORDER BY\n uid ASC\n "));
}
$users_results = db_query_range("\n SELECT\n DISTINCT uid\n FROM " . ($context['sandbox']['all_users'] ? '{users}' : '{users_roles}') . " WHERE " . ($context['sandbox']['all_users'] ? "" : "rid IN (" . implode(', ', $roles) . ") AND ") . "uid > %d\n ORDER BY\n uid ASC\n ", $context['sandbox']['last_uid'], 0, SCALD_ADMIN_ACTIONS_BATCH_LIMIT);
while ($users_raw = db_fetch_array($users_results)) {
$current = user_load($users_raw['uid']);
user_save($current);
$context['sandbox']['progress']++;
$context['sandbox']['last_uid'] = $users_raw['uid'];
}
$context['message'] = t('Updated @current of @total users.', array(
'@current' => $context['sandbox']['progress'],
'@total' => $context['sandbox']['total'],
));
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['total'];
}
function scald_settings_form() {
$form = array();
$form['intro'] = array(
'#value' => t("\n <h3>Scald Settings</h3>\n <p>Below you'll find some general Scald settings. Beware that some of\n them are very useful for debugging, but may completely kill performance.\n Use with caution.</p>\n "),
);
$form['scald_always_rebuild'] = array(
'#type' => 'checkbox',
'#default_value' => variable_get('scald_always_rebuild', FALSE),
'#title' => 'Always rebuild rendered content',
'#description' => "By default, Scald tries to agressively cache the atom's\n rendered content, by context and by actions available to the user viewing\n it. Checking this box, Scald will re-render the atom each time. This is a\n massive performance hit.",
);
return system_settings_form($form);
}