View source
<?php
define('SWEAVER_PATHS_EXCLUDE', "admin*\nnode/add*\nnode/*/edit\nnode/*/panel*\npanels/ajax*\nuser/*/edit\nbatch*\nwysiwyg_imageupload/*");
define('SWEAVER_SELECTORS_EXCLUDE', "#sweaver-frontend\n#admin-menu\n.colorpicker\n#sweaver-messages\n#sweaver-popup\n#follow-link\n#l10n-client");
define('SWEAVER_CLASSES_EXCLUDE', "clear\nclear-fix\nclear-block\nsweaver\nsweaver-hovered\nsweaver-clicked\nsweaver-clicked-temp");
define('SWEAVER_CTOOLS_ALLOWED_PROPERTIES', "-moz-border-radius\n-webkit-border-radius\nborder-top-right-radius\nborder-bottom-right-radius\nborder-bottom-left-radius\nborder-top-left-radius\nwebkit-border-top-right-radius\nwebkit-border-bottom-right-radius\nwebkit-border-bottom-left-radius\nwebkit-border-top-left-radius\nmoz-border-radius-topright\nmoz-border-radius-bottomright\nmoz-border-radius-bottomleft\nmoz-border-radius-topleft\nposition\ntop\nleft\nbottom\nright\nborder-collapse\nborder-spacing\nlist-style-image\nlist-style-type\nmin-width\nmax-width\nmin-height\nmax-height\nvisibility");
define('SWEAVER_SKIN', "default");
require_once 'sweaver.inc';
function sweaver_perm() {
return array(
'configure sweaver',
'use editor',
);
}
function sweaver_menu() {
module_load_include('inc', 'sweaver', 'sweaver.registry');
return _sweaver_menu();
}
function sweaver_theme() {
module_load_include('inc', 'sweaver', 'sweaver.registry');
return _sweaver_theme();
}
function sweaver_ctools_plugin_api($owner, $api) {
if ($owner == 'sweaver' && ($api == 'sweaver' || $api == 'plugins')) {
return array(
'version' => 1,
);
}
}
function sweaver_ctools_plugin_plugins() {
return array(
'cache' => TRUE,
'use hooks' => TRUE,
);
}
function sweaver_default_sweaver_selector() {
module_load_include('inc', 'sweaver', 'sweaver.registry');
return _sweaver_default_sweaver_selector();
}
function sweaver_default_sweaver_property() {
module_load_include('inc', 'sweaver', 'sweaver.registry');
return _sweaver_default_sweaver_property();
}
function sweaver_default_sweaver_type() {
module_load_include('inc', 'sweaver', 'sweaver.registry');
return _sweaver_default_sweaver_type();
}
function sweaver_sweaver_plugins() {
module_load_include('inc', 'sweaver', 'sweaver.registry');
return _sweaver_sweaver_plugins();
}
function sweaver_ctools_selectors_list() {
return sweaver_ctools_object_list('selector');
}
function sweaver_ctools_properties_list() {
return sweaver_ctools_object_list('property');
}
function sweaver_ctools_types_list() {
return sweaver_ctools_object_list('type');
}
function sweaver_ctools_object_list($object_type, $export_type = 2, $parent_check = FALSE) {
$list = array();
$objects = sweaver_object_load(NULL, $object_type, 'enabled');
foreach ($objects as $object) {
if ($object->export_type != $export_type) {
if ($parent_check) {
if ($object->property_type == 'parent') {
continue;
}
elseif (!empty($object->property_parent)) {
$object->description = $objects[$object->property_parent]->description . ': ' . $object->description;
}
}
$list[$object->name] = $object->description;
}
}
return $list;
}
function sweaver_export_sweaver_selector($object) {
return sweaver_export_sweaver_object($object, 'selector');
}
function sweaver_export_sweaver_property($object) {
return sweaver_export_sweaver_object($object, 'property');
}
function sweaver_export_sweaver_type($object) {
return sweaver_export_sweaver_object($object, 'type');
}
function sweaver_export_sweaver_object($object, $object_type) {
ctools_include('export');
sweaver_export_check_serialized_keys($object);
$output = ctools_export_object('sweaver_' . $object_type, $object, ' ');
return $output;
}
function sweaver_export_check_serialized_keys($object) {
if (isset($object->table)) {
$object_type = str_replace('sweaver_', '', $object->table);
$key = $object_type . '_options';
if (isset($object->{$key}) && !empty($object->{$key}) && is_string($object->{$key})) {
$object->{$key} = unserialize($object->{$key});
}
}
}
function sweaver_object_load($name = NULL, $map = NULL, $status = 'enabled') {
static $run = FALSE;
static $objects = NULL;
$object_type = is_array($map) ? $map[5] : $map;
if (!$run) {
if ($objects_cache = cache_get('sweaver')) {
$objects = $objects_cache->data;
}
else {
ctools_include('export');
$objects = new stdClass();
foreach (array(
'sweaver_selector',
'sweaver_property',
'sweaver_type',
) as $object_to_load) {
$loaded_objects = ctools_export_load_object($object_to_load);
foreach ($loaded_objects as $key => $object) {
$object_type_key = str_replace('sweaver_', '', $object->table);
if (!isset($object->disabled) || isset($object->disabled) && $object->disabled == FALSE) {
$objects->{$object_type_key}->enabled[$key] = $object;
}
$objects->{$object_type_key}->all[$key] = $object;
}
}
$sweaver = Sweaver::get_instance();
foreach (array_keys($sweaver
->get_plugins_registry(TRUE)) as $plugin_name) {
$sweaver_plugin = $sweaver
->get_plugin($plugin_name);
$sweaver_plugin
->sweaver_objects_alter($objects);
}
cache_set('sweaver', $objects);
}
$run = TRUE;
}
if ($name) {
return isset($objects->{$object_type}->all[$name]) ? $objects->{$object_type}->all[$name] : FALSE;
}
else {
return isset($objects->{$object_type}->{$status}) ? $objects->{$object_type}->{$status} : array();
}
}
function sweaver_get_plugin($plugin_name = NULL, $enabled = FALSE) {
$sweaver = Sweaver::get_instance();
if ($plugin_name == NULL) {
return $sweaver
->get_plugins_registry($enabled);
}
else {
return $sweaver
->get_plugin($plugin_name, $enabled);
}
}
function sweaver_init() {
$load_style =& ctools_static('load_style', TRUE);
if (sweaver_show_editor()) {
$sweaver = Sweaver::get_instance();
$load_style = FALSE;
$inline_js_settings = array(
'sweaver' => array(
'invokes' => array(),
),
);
$skin = variable_get('sweaver_skin', SWEAVER_SKIN);
drupal_add_js(drupal_get_path('module', 'sweaver') . '/sweaver_plugin.js', 'module');
drupal_add_css(drupal_get_path('module', 'sweaver') . '/skins/' . $skin . '/sweaver-' . $skin . '.css', 'module');
foreach (array_keys($sweaver
->get_plugins_registry(TRUE)) as $plugin_name) {
$sweaver_plugin = $sweaver
->get_plugin($plugin_name);
$sweaver_plugin
->sweaver_init();
$sweaver_plugin
->sweaver_form_css_js($inline_js_settings);
}
drupal_add_js($inline_js_settings, 'setting');
}
}
function sweaver_preprocess_page(&$vars) {
if (ctools_static('load_style')) {
$sweaver = Sweaver::get_instance();
if (ctools_static('load_style')) {
if (!empty($GLOBALS['custom_theme'])) {
$sweaver
->set_current_style($GLOBALS['custom_theme']);
}
}
$sweaver_style = $sweaver
->get_current_style();
if (isset($sweaver_style->css)) {
$css = $vars['css'];
$css_path = file_directory_path() . '/sweaver/sweaver_' . $sweaver
->get_theme_key() . '_' . $sweaver_style->style_id . '_' . $sweaver_style->type . '.css';
drupal_add_css($css_path, 'theme');
$vars['css']['all']['theme'][$css_path] = TRUE;
$vars['styles'] = drupal_get_css();
foreach (array_keys($sweaver
->get_plugins_registry(TRUE)) as $plugin_name) {
$sweaver_plugin = $sweaver
->get_plugin($plugin_name);
$sweaver_plugin
->sweaver_preprocess_page($vars);
}
}
}
}
function sweaver_footer($main = 0) {
if (sweaver_show_editor()) {
return drupal_get_form('sweaver_frontend') . '<div id="sweaver-messages"><div class="close">x</div><div class="message"></div></div>';
}
}
function sweaver_containers() {
return array(
'one' => t('Font'),
'two' => t('Background'),
'three' => t('Spacing'),
'four' => t('Empty'),
);
}
function sweaver_get_all_themes() {
$themes =& ctools_static('all_themes', array());
if (empty($themes)) {
$themes = array();
$result = db_query("SELECT filename, name, status, info FROM {system} WHERE type = 'theme' AND status = '1' ORDER BY name ASC");
while ($theme = db_fetch_object($result)) {
if ($theme->status) {
$theme->info = unserialize($theme->info);
$theme->prefix = isset($theme->info['engine']) ? $theme->info['engine'] : NULL;
$themes[$theme->name] = $theme;
}
}
}
return $themes;
}
function sweaver_get_theme_info($theme) {
$themes = sweaver_get_all_themes();
return $themes[$theme]->info;
}
function sweaver_theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
if (!$getsize || is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path))) {
$attributes = drupal_attributes($attributes);
$url = url($path, array(
'alias' => TRUE,
)) == $path ? $path : base_path() . $path;
return '<img src="' . check_url($url) . '" alt="' . check_plain($alt) . '" title="' . check_plain($title) . '" ' . (isset($image_attributes) ? $image_attributes : '') . $attributes . ' />';
}
}
function sweaver_session($value = NULL, $session_key = 'sweaver_editor_messages', $remove = FALSE, $return_string = TRUE) {
if (isset($session_key) && isset($value) && !$remove) {
if (!isset($_SESSION[$session_key])) {
$_SESSION[$session_key] = array();
}
$_SESSION[$session_key][] = $value;
}
elseif (isset($_SESSION[$session_key]) && !isset($value) && $remove) {
if (isset($_SESSION[$session_key])) {
unset($_SESSION[$session_key]);
}
}
elseif (isset($_SESSION[$session_key])) {
if ($return_string) {
$return = FALSE;
$values = $_SESSION[$session_key];
if (count($values) > 1) {
foreach ($values as $key => $value) {
$return .= $value . "\n";
}
}
elseif (isset($values[0])) {
$return = $values[0];
}
return $return;
}
else {
return $_SESSION[$session_key];
}
}
}
function sweaver_show_editor() {
static $run = FALSE;
static $return = FALSE;
if (!$run) {
$run = TRUE;
if (variable_get('sweaver_enabled', TRUE)) {
$path = drupal_get_path_alias($_GET['q']);
$page_match = drupal_match_path($path, variable_get('sweaver_paths', SWEAVER_PATHS_EXCLUDE));
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], variable_get('sweaver_paths', SWEAVER_PATHS_EXCLUDE));
}
$page_match = !(0 xor $page_match);
if (user_access('use editor') && $page_match) {
$return = TRUE;
}
}
}
return $return;
}
function sweaver_frontend(&$form_state) {
$form = array();
$weight = 1;
$form['#plugins'] = array();
$form['#theme'] = 'sweaver_plugin';
$form['#attributes'] = array(
'enctype' => 'multipart/form-data',
);
$plugins_order = variable_get('sweaver_plugins_weight', array());
$sweaver = Sweaver::get_instance();
foreach ($sweaver
->get_plugins_registry(TRUE) as $plugin_name => $plugin) {
$sweaver_plugin = $sweaver
->get_plugin($plugin_name);
$default_weight = isset($plugins_order[$plugin_name]) ? $plugins_order[$plugin_name] : $weight++;
if ($plugin_name == 'sweaver_plugin') {
$default_weight = -100;
}
$form['#plugins_order'][$plugin_name] = $default_weight;
$form['#plugins_full'][$plugin_name] = $plugin;
$plugin_form = $sweaver_plugin
->sweaver_form();
if (!empty($plugin_form)) {
$form[$plugin['name']]['form'] = $plugin_form;
if (isset($plugin['handler']['tab'])) {
$form[$plugin['name']]['#tab_name'] = isset($plugin['handler']['tab']) ? $plugin['handler']['tab'] : drupal_ucfirst($plugin_name);
$form[$plugin['name']]['#tab_description'] = isset($plugin['handler']['tab_description']) ? $plugin['handler']['tab_description'] : '';
}
}
}
$messages = sweaver_session();
sweaver_session(NULL, 'sweaver_editor_messages', TRUE);
$form['sweaver-editor-messages'] = array(
'#type' => 'hidden',
'#value' => trim($messages),
);
$form['#current_theme'] = $sweaver
->get_theme_key();
$form['destination'] = array(
'#type' => 'hidden',
'#value' => $_GET['q'],
);
return $form;
}
function sweaver_clear_cache() {
cache_clear_all();
drupal_clear_css_cache();
}
function sweaver_frontend_submit($form, &$form_state) {
$sweaver = Sweaver::get_instance();
foreach (array_keys($sweaver
->get_plugins_registry(TRUE)) as $plugin_name) {
$sweaver_plugin = $sweaver
->get_plugin($plugin_name);
$sweaver_plugin
->sweaver_form_submit($form, $form_state);
}
drupal_goto();
}
function sweaver_menu_callback($settings) {
$plugin_name = $settings['plugin'];
$callback_method = isset($settings['callback_method']) ? $settings['callback_method'] : 'sweaver_menu_callback';
$return_method = isset($settings['return_method']) ? $settings['return_method'] : 'drupal_get_form';
$js = isset($settings['js']) ? TRUE : FALSE;
if ($sweaver_plugin = Sweaver::get_instance()
->get_plugin($plugin_name, TRUE)) {
$output = $sweaver_plugin
->{$callback_method}();
if (!empty($output)) {
if ($return_method == 'drupal_get_form') {
return drupal_get_form('sweaver_menu_callback_form', $output, $plugin_name, $callback_method);
}
elseif (isset($js)) {
exit(drupal_to_js($output));
}
elseif (!empty($return_method) && function_exists($return_method)) {
return $return_method($output);
}
else {
return $output;
}
}
}
return t('No page found or you do not have sufficient permissions to access the page.');
}
function sweaver_menu_callback_form($form_state, $form, $plugin_name, $callback_method) {
$form['#plugin_name'] = $plugin_name;
$form['#callback_method'] = $callback_method;
return $form;
}
function sweaver_menu_callback_form_validate($form, &$form_state) {
$sweaver_plugin = Sweaver::get_instance()
->get_plugin($form['#plugin_name']);
$callback_validate_function = $form['#callback_method'] . '_validate';
if (method_exists($sweaver_plugin, $callback_validate_function)) {
$sweaver_plugin
->{$callback_validate_function}($form, $form_state);
}
}
function sweaver_menu_callback_form_submit($form, &$form_state) {
$sweaver_plugin = Sweaver::get_instance()
->get_plugin($form['#plugin_name']);
$callback_submit_function = $form['#callback_method'] . '_submit';
if (method_exists($sweaver_plugin, $callback_submit_function)) {
$sweaver_plugin
->{$callback_submit_function}($form, $form_state);
}
}