summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJospeh Z2013-10-28 04:49:33 (GMT)
committer Jospeh Z2013-10-28 04:49:33 (GMT)
commitb36116a451292b02ae39ff65d0577066a2f7af02 (patch)
tree6f8cf698399853f2427c2721382cc6c15f926a18
parent1f448eb31dd18721748c1ee7b63ec002d2fd8509 (diff)
Add button edit handler/Update module install file
-rw-r--r--includes/socialshare.admin.form.inc79
-rw-r--r--includes/socialshare.admin.theme.inc2
-rw-r--r--socialshare.install16
-rw-r--r--socialshare.module20
4 files changed, 110 insertions, 7 deletions
diff --git a/includes/socialshare.admin.form.inc b/includes/socialshare.admin.form.inc
index b9215b8..6b79ad7 100644
--- a/includes/socialshare.admin.form.inc
+++ b/includes/socialshare.admin.form.inc
@@ -183,6 +183,83 @@ function _socialshare_button_add_submit($form, &$form_state) {
}
/**
+ * Edit handler for button.
+ */
+function _socialshare_button_edit($form, &$form_state, $edit = array()) {
+ $machine_name = arg(5);
+ // Check if machine_name is available.
+ if (empty($machine_name) || !socialshare_button_machine_name_load($machine_name)) {
+ $message = t('This button is not available.');
+ drupal_set_message($message, 'error');
+ return FALSE;
+ }
+
+ $buttons_serialize = variable_get('socialshare_buttons', _socialshare_buttons_default());
+ $buttons = unserialize($buttons_serialize);
+ if (is_array($buttons) && count($buttons)) {
+ $button = $buttons[$machine_name];
+ }
+
+ $form['button_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name'),
+ '#default_value' => $button->button_name,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ );
+ $form['button_machine_name'] = array(
+ '#type' => 'machine_name',
+ '#default_value' => $button->button_machine_name,
+ '#maxlength' => 21,
+ '#machine_name' => array(
+ 'exists' => 'socialshare_button_machine_name_load',
+ 'source' => array('button_name'),
+ ),
+ );
+ $form['button_codes'] = array(
+ '#title' => t('Button share codes'),
+ '#type' => 'textarea',
+ '#description' => t('Share codes such as url or javascript codes'),
+ '#wysiwyg' => FALSE,
+ '#required' => TRUE,
+ '#default_value' => $button->button_codes,
+ );
+ $form['button_icon'] = array(
+ '#title' => t('Upload button/icon'),
+ '#type' => 'managed_file',
+ '#description' => t('Allowed extensions: gif png jpg jpeg'),
+ '#default_value' => $button->button_icon,
+ '#required' => FALSE,
+ '#upload_validators' => array(
+ 'file_validate_extensions' => array(
+ 'gif png jpg jpeg',
+ ),
+ // Pass the maximum file size in bytes.
+ 'file_validate_size' => array(1 * 1024 * 1024),
+ ),
+ '#upload_location' => 'public://socialshare/icons/',
+ );
+ $form['button_enabled'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enabled'),
+ '#default_value' => $button->button_enabled,
+ );
+
+ $form['button_weight'] = array(
+ '#type' => 'weight',
+ '#title' => t('Weight'),
+ '#delta' => 50,
+ '#default_value' => $button->button_weight,
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ );
+ return $form;
+}
+
+/**
* Callback to load existing machine name.
*/
function socialshare_button_machine_name_load($name) {
@@ -191,5 +268,7 @@ function socialshare_button_machine_name_load($name) {
if (array_key_exists($name, $buttons)) {
$button[] = $buttons[$name]->button_machine_name;
return reset($button);
+ } else {
+ return FALSE;
}
}
diff --git a/includes/socialshare.admin.theme.inc b/includes/socialshare.admin.theme.inc
index b3dea51..ebbfb73 100644
--- a/includes/socialshare.admin.theme.inc
+++ b/includes/socialshare.admin.theme.inc
@@ -32,7 +32,7 @@ function theme_socialshare_admin_buttons_list($variables = NULL) {
'data' => $value->button_weight,
);
$row[] = array(
- 'data' => l(t('Edit'), 'admin/config/socialshare/button/edit/' . $value->button_machine_name) . ' | ' . l(t('Delete'), 'admin/config/socialshare/button/del/' . $value->button_machine_name),
+ 'data' => l(t('Edit'), 'admin/config/socialshare/buttons/edit/' . $value->button_machine_name) . ' | ' . l(t('Delete'), 'admin/config/socialshare/buttons/del/' . $value->button_machine_name),
);
$rows[] = $row;
}
diff --git a/socialshare.install b/socialshare.install
index aa1ace8..a81e100 100644
--- a/socialshare.install
+++ b/socialshare.install
@@ -6,9 +6,25 @@
*/
/**
+ * Implements hook_install().
+ */
+function socialshare_install() {
+ // Create socialshare icon folder.
+ $dir = SOCIALSHARE_ICON_PATH;
+ file_prepare_directory($dir, FILE_CREATE_DIRECTORY);
+ // Message after installation.
+ $message = t('SocialShare module is installed.');
+ $message .= l(t('Configure here'), 'admin/config/socialshare');
+ drupal_set_message($message);
+}
+
+/**
* Implements hook_uninstall().
*/
function socialshare_uninstall() {
+ // Remove socialshare icon folder.
+ $dir = 'public://socialshare';
+ file_unmanaged_delete_recursive($dir);
// Delete module's variables.
variable_del('socialshare_buttons');
variable_del('socialshare_display_pages_enabled');
diff --git a/socialshare.module b/socialshare.module
index 964777a..2c332d6 100644
--- a/socialshare.module
+++ b/socialshare.module
@@ -6,6 +6,11 @@
*/
/**
+ * Default settings.
+ */
+define('SOCIALSHARE_ICON_PATH', 'public://socialshare/icons');
+
+/**
* Implements hook_menu().
*/
function socialshare_menu() {
@@ -62,7 +67,7 @@ function socialshare_menu() {
'access arguments' => array(
'access socialshare administer',
),
- 'type' => MENU_CALLBACK,
+ 'type' => MENU_NORMAL_ITEM,
'file' => 'includes/socialshare.admin.inc',
);
$items['admin/config/socialshare/buttons/edit'] = array(
@@ -75,7 +80,7 @@ function socialshare_menu() {
'access arguments' => array(
'access socialshare administer',
),
- 'type' => MENU_CALLBACK,
+ 'type' => MENU_NORMAL_ITEM,
'file' => 'includes/socialshare.admin.inc',
);
$items['admin/config/socialshare/buttons/del'] = array(
@@ -200,7 +205,7 @@ function _socialshare_buttons_default() {
$button_fb->button_enabled = TRUE;
$button_fb->button_weight = '0';
- $buttons[$button_fb->button_name] = $button_fb;
+ $buttons[$button_fb->button_machine_name] = $button_fb;
$button_twitter = new stdClass();
$button_twitter->button_name = 'Twitter';
@@ -210,7 +215,7 @@ function _socialshare_buttons_default() {
$button_twitter->button_enabled = TRUE;
$button_twitter->button_weight = '1';
- $buttons[$button_twitter->button_name] = $button_twitter;
+ $buttons[$button_twitter->button_machine_name] = $button_twitter;
$button_linkedin = new stdClass();
$button_linkedin->button_name = 'LinkedIn';
@@ -220,7 +225,7 @@ function _socialshare_buttons_default() {
$button_linkedin->button_enabled = TRUE;
$button_linkedin->button_weight = '2';
- $buttons[$button_linkedin->button_name] = $button_linkedin;
+ $buttons[$button_linkedin->button_machine_name] = $button_linkedin;
$button_gplus = new stdClass();
$button_gplus->button_name = 'Google Plus';
@@ -230,7 +235,7 @@ function _socialshare_buttons_default() {
$button_gplus->button_enabled = TRUE;
$button_gplus->button_weight = '3';
- $buttons[$button_gplus->button_name] = $button_gplus;
+ $buttons[$button_gplus->button_machine_name] = $button_gplus;
return serialize($buttons);
}
@@ -294,6 +299,9 @@ function _socialshare_allow() {
return FALSE;
}
if (arg(0) == 'node' && is_numeric(arg(1))) {
+ if(arg(2) == 'add' || arg(2) == 'edit') {
+ return FALSE;
+ }
// Only display widget with content type allowed.
$node = menu_get_object();
$node_type = $node->type;