summaryrefslogtreecommitdiffstats
path: root/API.txt
blob: d925073354fe1d4f7ec6cd22a9d62e692aacb3e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
Table of contents
------------------

1. Hook for cTools.
2. Hooks for registering selectors, properties and types.
3. Plugins hook.
4. Plugin class example.
5. sweaver_get_plugin().
6. Images handler.
7. Session handling
8. Sweaver popups.
9. General functions.
10. General JS functions.
11. General CSS styles.
12. Skins
13. Theme extensions.
14. hook_sweaver_action().

------------------------------------------------------
1. Hook for cTools
------------------------------------------------------

/**
 * Implementation of hook_ctools_plugin_api().
 */
function hook_ctools_plugin_api($owner, $api) {
  if ($owner == 'sweaver' && $api == 'sweaver') {
    return array('version' => 1);
  }
}

---------------------------------------------------------
2. Hooks for registering selectors, properties and types
---------------------------------------------------------

/**
 * Implementation of hook_default_sweaver_selector().
 */
function hook_default_sweaver_selector() {

  $selectors = array();

  $selector = new stdClass;
  $selector->api_version = 1;
  $selector->disabled = FALSE; // Set this to true if you want to disable this by default.
  $selector->name = 'machine_name';
  $selector->description = 'Description';
  $selector->selector_selector = '.selector'; // css selector.
  $selector->selector_highlight = FALSE; // Whether to highlight the selector in the active path. 
  $selectors['machine_name'] = $selector;
  
  return $selectors;
}

/**
 * Implementation of hook_default_sweaver_property().
 */
function hook_default_sweaver_property() {

  $propertys = array();

  // Font.
  $property = new stdClass;
  $property->api_version = 1;
  $property->disabled = FALSE; // Set this to true if you want to disable this by default.
  $property->name = 'machine_name';
  $property->description = 'Description';
  $property->property = '';  // The actual css property. Seperate multiple values by spaces.
  $property->property_parent = ''; // Wether this property has a parent.
  $property->property_type = 'select'; // Can be select, slider, image, color or parent.
  // Prefix or suffix: eg: padding has suffix 'px', url has prefix 'url(' and suffix ');'
  $property->property_prefix = '';
  $property->property_suffix = '';
  // Slider min & max - only applicable for slider.
  $property->property_slider_min = ''; // Minimum for slider  , usually 1.
  $property->property_slider_max = ''; // Maximum for slider
  // Options are only applicable for select.
  $property->property_options = array(
        'option_1' => 'Readable option 1',
        'option_2' => 'Readable option 2',
        'option_2' => 'Readable option 3',
      );
  $propertys['font-machine_name'] = $property;

  // Yes you need to return propertys, that's the way Ctools works :)
  return $propertys;
}

/**
 * Implementation of hook_sweaver_type().
 */
function sweaver_default_sweaver_type() {

  $types = array();

  $type = new stdClass;
  $type->api_version = 1;
  $type->disabled = FALSE;
  $type->name = 'machine_name';
  $type->description = 'Description';
  $type->type_options = array(
    'property_1' => 'property_1',
    'property_2' => 'property_2',
    'property_3' => 'property_2',
  );
  $types['machine_name'] = $type;
  
  return $types;
}


---------------------------------------------------------
3. Plugins hook.
---------------------------------------------------------

/**
 * Implementation of hook_sweaver_plugins().
 */
function hook_sweaver_plugins() {
  $plugins = array();
  
  $plugins['yourpluginname'] = array(
    'handler' => array(
      'tab' => t('Tab name'), // If you want to do something in the frontend.
      'tab_description' => t('Description of your plugin in frontend'),
      'path' => drupal_get_path('module', 'yourmodulename') .'/plugins/yourpluginname',
      'file' => 'yourpluginname.inc',
      'class' => 'yourclassnameusuallythesameasyourpluginname',
      'parent' => 'sweaver_plugin', // This is required.
    ),
  );
  
  return $plugins;
}

---------------------------------------------------------
4. Plugin class example.
---------------------------------------------------------

/**
 * Your plugin
 *
 * All methods are optional.
 */
class pluginname extends sweaver_plugin {

  /**
   * Return module dependencies.
   */
  function sweaver_dependencies() {
    return array('module');
  }

  /**
   * Menu registry.
   */
  function sweaver_menu(&$weight, $page_arguments, $base) {
    // $page_arguments = array('plugin' => 'name_of_your_plugin'); 
    //  $base = array(
    //    'access arguments' => array('configure sweaver'),
    //    'page callback' => 'sweaver_menu_callback',
    //  );
    // You can use these to add to your menu items.
    // Other stuff you can return in page arguments:
    // callback_method: defaults to sweaver_menu_callback - optional.
    // return_method : default to drupal_get_form - optional
    // Return menu items for Drupal.
  }

  /**
   * Theme registry.
   */
  function sweaver_theme() {
    // Return theming functions for Drupal.
  }

  /**
   * Init function.
   */
  function sweaver_init() {
    // Do stuff during hook_init() of Drupal.
  }

  /**
   * Sweaver objects alter.
   */
  function sweaver_objects_alter(&$objects) {}

  /**
   * Sweaver form.
   */
  function sweaver_form() {
    return array();
  }

  /**
   * Sweaver form render.
   */
  function sweaver_form_render(&$vars, &$form, $plugin) {
    // Do some extra rendering on the form.
  }

  /**
   * Frontend css and js.
   */
  function sweaver_form_css_js(&$inline_settings) {
    // Add css, js and manipulate the inline settings of sweaver.
  }

  /**
   * Frontend form submit.
   */
  function sweaver_form_submit($form, &$form_state) {
    // Do something with the submitted values.
  }
  
  /**
   * Default menu callback.
   */
  function sweaver_menu_callback() {
    // Return a form or simply some other output.
    // Must return a form array() by default. This
    // is the default method you need to implement.
    // This makes is possible to have menu callbacks in your
    // class without having to create a new file.
    // All plugins - except for editor.admin.inc' use this
    // technique. See sweaver_menu_callback() for options.
  }

  /**
   * Default sweaver menu callback validate.
   */
  function sweaver_menu_callback_validate($form, &$form_state) {
    // Validate the submission.
  }

  /**
   * Default sweaver menu callback submit
   */
  function sweaver_menu_callback_submit($form, &$form_state) {
    // Do something with the submitted values.
  }
  
  /**
   * Return false to not show editor.
   */
  public function show_editor() {
  }

  /**
   * Return true to allow access and false to deny.
   */
  public function sweaver_menu_access_callback($args) {
  }  
}

------------------------------------------------------
5. sweaver_get_plugin().
------------------------------------------------------

.You can use sweaver_get_plugin to get an object. This function will
load the plugin and return the class if found.

$object = sweaver_get_plugin('plugin_name');
$object->do_some_method();

------------------------------------------------------
6. Images handler.
------------------------------------------------------

The editor searches for a class which implements a method called sweaver_images_handler.
By default, the images plugin which comes in the sweaver module provides extra images.
You can change this by setting the variable 'sweaver_plugin_handle_images' to the name
of the plugin you want. The plugin itself must implement following method:

myclass extends sweaver_plugin {
  function sweaver_images_handler(&$images) {
    $images['file_path_1'] = 'Real name 1'; 
    $images['file_path_2'] = 'Real name 2'; 
  }
}

------------------------------------------------------
7. Session handling
------------------------------------------------------

sweaver_session($value = NULL, $session_key = 'sweaver_editor_messages', $remove = FALSE, $return = 'string')

Set or return session variables which you can easily use througout the plugin system.
Much easier than using $_SESSION variables. This function does it all for you.
Use it as much as you can.

------------------------------------------------------
8. Sweaver popups.
------------------------------------------------------

You can put forms in a sweaver popup, which we do for example in the themesettings plugin.
Following things in the sweaver_form method will make sure this happens:

    $form['#popups'] = array(); // Initialize the popups array.
    $form['#popups'][] = $key; // Put a FAPI key in the popups array.
    // Link class: popup-link This will trigger the popup.
    // The link needs an id with at least 'link' in the name. The form
    // it has to show needs the same id, but with 'link' replaced as 'data'.
    
For inspiration, take a look at plugins/sweaver_plugin_themesettings/sweaver_plugin_themesettings.inc.

------------------------------------------------------
9. General functions.
------------------------------------------------------

- sweaver_get_current_style($reset = FALSE) {}
  Returns the css for the theme.
- sweaver_get_theme_info($theme) {}
  Returns the theme info for the theme.

------------------------------------------------------
10. General JS functions.
------------------------------------------------------

There are a couple of JS functions you can use in your plugins.

- Drupal.Sweaver.invokes.processCSS()
  Must a return CSS definitions to write for the editor.
  Implemented in editor and custom css plugin. 
- Drupal.Sweaver.switchTab(remove_tab, show_tab) {}
  Switch to a tab in the editor
- Drupal.Sweaver.setMessage(messages) {}
  Sets a message above the editor. Times out after 5 seconds.
- Drupal.Sweaver.showPopup(message) {}
  Shows a popup screen with any content you like. 
  Gets a close button.
- Drupal.Sweaver.hidePopup() {}
  Closes the popup screen.

------------------------------------------------------
11. General CSS styles.
------------------------------------------------------

There are several css classes which you can use which will do all kinds of stuff

- popup-link: put this on a link and this will trigger a sweaver popup
- sweaver-switch-to-style: adds a brush icon
- container: lets a div float
- container-1 to container-4: determines the width (from 25% to 100%)
- float-left: floats to left
- form-floater: makes form items and submits float

------------------------------------------------------
12. Skins.
------------------------------------------------------
You can create new skins for the editor if you like. Simply
create a new directory with your name and copy the files which
are found in default, rename them to the name of your new skin
and adjust them to your likings. On the general configuration screen, 
you can select the skin you like.

The variable in the database is 'sweaver_skin'.

------------------------------------------------------
13. Theme extensions.
------------------------------------------------------

1. Palettes

Every theme can define color palettes. These palettes are
extra css files that can be added to your theme and that
overwrite the default css.

You can add a palette and 5 preview colors in your .info file, e.g.:

sweaver[palettes][pink][name] = Pink
sweaver[palettes][pink][file] = palettes/pink.css
sweaver[palettes][pink][colors][] = #f98cf0
sweaver[palettes][pink][colors][] = #af63a9
sweaver[palettes][pink][colors][] = #af63a9
sweaver[palettes][pink][colors][] = #cbb2c9
sweaver[palettes][pink][colors][] = #cbb2c9 

2. Selectors

You can also define selectors per theme in the info file, eg:

sweaver[selectors][body] = Body
sweaver[selectors][h1] = Heading 1
...

The order is how you define it in the info file.
In the backend you can select if these selectors
are to be used instead of those in the database.

Those selectors will be exclusive. Which means that the
user will only be able to select and modify those defined selectors

To define inclusive selectors (which will be added to others 
created in the regestry) you need to add options to your selectors

sweaver[selectors][h4][name] = h4
sweaver[selectors][h4][description] = Heading 4
sweaver[selectors][h4][selector_highlight] = TRUE
sweaver[selectors][h4][weight] = 20
sweaver[selectors][h4][type] = add

 - The name must contain only lowercase letters, numbers, underscores or hyphens
 and must be unique.
 - The selector description is the text shown to the Sweaver front end user
 - The selector_highlight property define weither or not the selector should be
 highlighted by default
 - The weight is a very important element as it define the priority of this
 selector on others. A value between 20 and 50 is advisable for major selectors
 and a value between 70 and 100 for minors ones.
 - The type is either set as add for inclusive or replace f r excluse selector

Note: if you add new theme extensions but they don't show up,
then you need to clear the theme registry.

------------------------------------------------------
14. hook_sweaver_action($action, $arguments).
------------------------------------------------------

If you want other modules to act on certain actions happening in sweaver use
module_invoke_all('sweaver', 'action_name', $arguments);

Currently the Theme switch plugin is the first plugin calling this
so other modules can perform actions when switching theme.