smileys.module

// $Id: smileys.module,v 1.42.2.1 2005/04/24 17:22:22 unconed Exp $

function smileys_help($section = 'admin/help#smileys') {
switch ($section) {
case 'admin/modules#description':
return t('Replaces smileys inside posts with images.');
case 'admin/filters/smileys':
return t('Here you can edit the smileys that are recognised by your site.');
}
}

function smileys_perm() {
return array('administer smileys');
}

function smileys_filter_tips($delta, $format, $long = false) {
if ($long) {
return t('If you include a textual smiley in your post (see chart below), it will be replaced by a graphical smiley.') . '
' . smileys_table();
}
else {
$GLOBALS['display_smileys_block'] = true;
return t('Textual smileys will be replaced with graphical ones.');
}
}

function _smileys_list($id = null) {


$smileys_data = variable_get('smileys_data', 'YTo0OntpOjA7Tzo4OiJzdGRDbGFzcyI6NTp7czo4OiJhY3JvbnltcyI7czozOiI6LUQiO3M6NToiaW1hZ2UiO3M6NDQ6Imh0dHA6Ly9zZXJhc2VyYS5vcmcvc21pbGV5cy9pY29uX2JpZ2dyaW4uZ2lmIjtzOjExOiJkZXNjcmlwdGlvbiI7czoxMDoiVmVyeSBoYXBweSI7czoxMDoic3RhbmRhbG9uZSI7czoxOiIxIjtzOjI6ImlkIjtzOjE0OiJzNDNmZWY4ZTUwNzU0NyI7fWk6MTtPOjg6InN0ZENsYXNzIjo1OntzOjg6ImFjcm9ueW1zIjtzOjY6IjotKSA6KSI7czo1OiJpbWFnZSI7czo0MjoiaHR0cDovL3NlcmFzZXJhLm9yZy9zbWlsZXlzL2ljb25fc21pbGUuZ2lmIjtzOjExOiJkZXNjcmlwdGlvbiI7czo1OiJTbWlsZSI7czoxMDoic3RhbmRhbG9uZSI7czoxOiIwIjtzOjI6ImlkIjtzOjE0OiJzNDNmZWY5MTQ3N2EyOCI7fWk6MjtPOjg6InN0ZENsYXNzIjo1OntzOjg6ImFjcm9ueW1zIjtzOjY6IjotKCA6KCI7czo1OiJpbWFnZSI7czo0MDoiaHR0cDovL3NlcmFzZXJhLm9yZy9zbWlsZXlzL2ljb25fc2FkLmdpZiI7czoxMToiZGVzY3JpcHRpb24iO3M6MzoiU2FkIjtzOjEwOiJzdGFuZGFsb25lIjtzOjE6IjEiO3M6MjoiaWQiO3M6MTQ6InM0M2ZlZjkzMjhkOWIxIjt9aTozO086ODoic3RkQ2xhc3MiOjU6e3M6ODoiYWNyb255bXMiO3M6MTM6IjstKSA6d2luazogOykiO3M6NToiaW1hZ2UiO3M6NDE6Imh0dHA6Ly9zZXJhc2VyYS5vcmcvc21pbGV5cy9pY29uX3dpbmsuZ2lmIjtzOjExOiJkZXNjcmlwdGlvbiI7czo0OiJXaW5rIjtzOjEwOiJzdGFuZGFsb25lIjtzOjE6IjEiO3M6MjoiaWQiO3M6MTQ6InM0M2ZlZjk1YTQ2Y2VjIjt9fQ==');
$smileys_array = unserialize(base64_decode($smileys_data));

if(!is_array($smileys_array)) {
Return array();
} else {
if (is_null($id)) {
Return $smileys_array;
} else {
foreach($smileys_array as $smileys_object) {
if($smileys_object->id == $id) {
$new_smileys_array[] = $smileys_object;
Return $new_smileys_array;
}
}
}
}
}

function _smileys_delete($id) {

$smileys_array = _smileys_list();
$smileys_object = (object)null;


$new_smileys_array = array();
foreach($smileys_array as $smileys_object) {
if($smileys_object->id != $id) {
$new_smileys_array[] = $smileys_object;
}
}
$smileys_array = $new_smileys_array;



// Let's make all of the data one string now!
$data = base64_encode(serialize($smileys_array));

variable_set('smileys_data', $data);

Return true;
}


function _smileys_save($acronyms, $image, $description, $standalone, $id = null) {


$smileys_array = _smileys_list();

if(!is_null($id)) {
$new_smileys_array = array();
foreach($smileys_array as $smileys_object) {
if($smileys_object->id == $id) {
$smileys_object->acronyms = $acronyms;
$smileys_object->image = $image;
$smileys_object->description = $description;
$smileys_object->standalone = $standalone;
$new_smileys_array[] = $smileys_object;
} else {
$new_smileys_array[] = $smileys_object;
}
}
$smileys_array = $new_smileys_array;
} else {
$smileys_object->acronyms = $acronyms;
$smileys_object->image = $image;
$smileys_object->description = $description;
$smileys_object->standalone = $standalone;
$smileys_object->id = uniqid('s');

$smileys_array[] = $smileys_object;
}

$data = base64_encode(serialize($smileys_array));
variable_set('smileys_data', $data);

Return true;

}

function smileys_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Smileys on submission pages');
return $blocks;
}
else if ($op == 'view') {
switch ($delta) {
case 0:
$block['subject'] = t('Smileys');
$block['content'] = $GLOBALS['display_smileys_block'] ? smileys_table() : '';
return $block;
}
}
}

function smileys_table() {
$content .= '
'; $content .= '
. $smiley->image .'" title="'. $alt .'" alt="'. $alt .'" />  '. $alt .'
'; return $content; } function smileys_filter($op, $delta = 0, $format = -1, $text = "") { switch ($op) { case 'list': return array(0 => t('Smileys filter')); case 'description': return smileys_help('admin/modules#description'); case 'settings': return form_group(t('Smileys filter'), t('You can define a global list of smileys on the smileys settings page.', array('%url' => url('admin/filters/smileys')))); case "process": return smileys_filter_process($text); default: return $text; } } function smileys_filter_process($text) { $text = ' '. $text .' '; $list = _smileys_list(); foreach ($list as $smiley) { $acronyms = explode(" ", $smiley->acronyms); $alt = str_replace('\\', '\\\\', check_plain($smiley->description)); foreach ($acronyms as $a) { if ($smiley->standalone) $text = eregi_replace("([ ,\.\?!:\(\)\r\n\\>])". preg_quote($a) ."([ ,\.\?!:\(\)\r\n\\>])", "\\1\"". ($smiley->image) ."\" title=\"". $alt ."\" alt=\"". $alt ."\" />\\2", $text); else $text = eregi_replace(preg_quote($a), '. ($smiley->image) .'" title="'. $alt .'" alt="'. $alt .'" />', $text); } } $text = substr($text, 1, -1); return $text; } function smileys_menu($may_cache) { $items = array(); if ($may_cache) { $access = user_access('administer smileys'); $items[] = array( 'path' => 'admin/filters/smileys', 'title' => t('smileys'), 'callback' => 'smileys_admin_overview', 'access' => $access); $items[] = array( 'path' => 'admin/filters/smileys/list', 'title' => t('list'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array( 'path' => 'admin/filters/smileys/add', 'title' => t('add'), 'callback' => 'smileys_admin_add', 'access' => $access, 'type' => MENU_LOCAL_TASK); $items[] = array( 'path' => 'admin/filters/smileys/edit', 'title' => t('edit'), 'callback' => 'smileys_admin_edit', 'access' => $access, 'type' => MENU_CALLBACK); } return $items; } function smileys_admin_list() { $header = array(t('smiley'), t('acronyms'), t('description'), t('operations')); $rows = array(); $list = _smileys_list(); foreach ($list as $smiley) { $rows[] = array( '. $smiley->image .'" alt="'. check_plain($smiley->description) .'" />', check_plain($smiley->acronyms), $smiley->description, l(t('edit smiley'), 'admin/filters/smileys/edit/'. $smiley->id) ); } $output .= theme('table', $header, $rows); return $output; } function smileys_admin_form($edit = array()) { if ($edit['id']) { $form .= form_hidden('id', $edit['id']); } $form .= form_textfield(t('Acronyms'), 'acronyms', $edit['acronyms'], 16, 255, t('Enter a list of shorthands for the smiley you wish to add, separated by spaces. E.g. \':) ;) :smile:\'')); $form .= form_textfield(t('Image URL'), 'image', $edit['image'], 50, 255, t('Enter the URL of the smiley-image relative to the root of your Drupal site. E.g. \'images/smileys/happy.png\'.')); $form .= form_textfield(t('Description'), 'description', $edit['description'], 50, 64, t('A short description of the emotion depicted to be used as tooltip for the image. E.g. \'Laughing out loud\'.')); $form .= form_checkbox(t('Stand-alone'), 'standalone', 1, $edit['standalone'], t('When checked, the smiley will only be inserted when an acronym is found as a separate word. This is useful for preventing accidental smileys with short acronyms.')); $form .= form_submit(t('Save Smiley')); if ($edit['id']) { $form .= form_submit(t('Delete Smiley')); } return form($form, 'post'); } function smileys_admin_validate($edit) { if (trim($edit['acronyms']) == '') { form_set_error('acronyms', t('Please enter an acronym for your smiley.')); } if ($edit['image'] == '') { form_set_error('image', t('Please enter the URL of the smiley image.')); } return !form_get_errors(); } function smileys_admin_save($edit) { if ($edit['id']) { _smileys_save($edit['acronyms'], $edit['image'], $edit['description'], $edit['standalone'], $edit['id']); $message = t('Updated smiley: %smiley', array('%smiley' => $edit['acronyms'])); } else { _smileys_save($edit['acronyms'], $edit['image'], $edit['description'], $edit['standalone']); $message = t('Added smiley: %smiley', array('%smiley' => $edit['acronyms'])); } watchdog('regular', $message); drupal_set_message($message); } function smileys_admin_delete($smiley) { if ($smiley['id']) { _smileys_delete($smiley["id"]); $message = t('Deleted smiley: %smiley', array('%smiley' => $smiley['acronyms'])); watchdog('regular', $message); drupal_set_message($message); } } function smileys_admin_add($smiley = NULL) { $edit = $smiley ? $smiley : $_POST['edit']; if ($_POST['op'] == t('Save Smiley')) { if (smileys_admin_validate($edit)) { smileys_admin_save($edit); drupal_goto('admin/filters/smileys'); } } else if ($_POST['op'] == t('Delete Smiley')) { if ($edit['id']) { smileys_admin_delete($edit); drupal_goto('admin/filters/smileys'); } } $output .= smileys_admin_form($edit); print theme('page', $output); } function smileys_admin_edit() { if ($_POST['op'] == NULL) { //satria array no alefany fa tsy object :-( $tmp_smiley = _smileys_list(arg(4)); $tmp_smiley_obj = $tmp_smiley[0]; $smiley = (array)$tmp_smiley_obj; } smileys_admin_add($smiley); } function smileys_admin_overview() { $output = smileys_admin_list(); print theme('page', $output); } ?>
Annunci

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...