function widget($args) { extract($args); global $rcl_group, $user_ID; if (!$user_ID || rcl_is_group_can('admin')) { return false; } if ($rcl_group->current_user == 'banned') { return false; } if (rcl_is_group_can('reader')) { echo $before; echo '<form method="post">' . '<input type="submit" class="recall-button" name="group-submit" value="' . __('Leave group', 'wp-recall') . '">' . '<input type="hidden" name="group-action" value="leave">' . wp_nonce_field('group-action-' . $user_ID, '_wpnonce', true, false) . '</form>'; echo $after; } else { if (rcl_get_group_option($rcl_group->term_id, 'can_register')) { echo $before; if ($rcl_group->group_status == 'open') { echo '<form method="post">' . '<input type="submit" class="recall-button" name="group-submit" value="' . __('Join group', 'wp-recall') . '">' . '<input type="hidden" name="group-action" value="join">' . wp_nonce_field('group-action-' . $user_ID, '_wpnonce', true, false) . '</form>'; } if ($rcl_group->group_status == 'closed') { $requests = rcl_get_group_option($rcl_group->term_id, 'requests_group_access'); if ($requests && false !== array_search($user_ID, $requests)) { echo '<h3 class="title-widget">' . __('The request for access sent', 'wp-recall') . '</h3>'; } else { echo '<form method="post">' . '<input type="submit" class="recall-button" name="group-submit" value="' . __('Apply for membership', 'wp-recall') . '">' . '<input type="hidden" name="group-action" value="ask">' . wp_nonce_field('group-action-' . $user_ID, '_wpnonce', true, false) . '</form>'; } } echo $after; } } }
function __construct($atts) { global $editpost, $group_id, $rcl_options, $user_ID, $formData; $editpost = false; $this->can_edit = true; extract(shortcode_atts(array('cats' => false, 'id' => 1, 'id_upload' => 'upload-public-form', 'accept' => 'image/*', 'post_type' => 'post', 'type_editor' => null, 'wp_editor' => null, 'group_id' => $group_id), $atts)); $this->post_type = $post_type; $this->id_upload = $id_upload; $this->terms = $cats; $this->form_id = $id; $this->accept = $accept; if (!isset($wp_editor)) { if (isset($rcl_options['wp_editor'])) { $cnt = count($rcl_options['wp_editor']); if ($cnt == 1) { $type = $rcl_options['wp_editor'][0]; } else { $type = 3; } } $this->wp_editor = isset($type) ? $type : 0; } else { $this->wp_editor = $wp_editor; } $this->type_editor = $type_editor; if (!isset($this->type_editor)) { $this->type_editor = isset($rcl_options['type_editor-' . $this->post_type]) ? $rcl_options['type_editor-' . $this->post_type] : $rcl_options['type_text_editor']; } if (isset($_GET['rcl-post-edit'])) { $this->post_id = $_GET['rcl-post-edit']; $editpost = get_post($this->post_id); $this->post_type = $editpost->post_type; if ($this->post_type == 'post-group') { if (!rcl_can_user_edit_post_group($this->post_id) && !current_user_can('edit_post', $this->post_id)) { $this->can_edit = false; } $group_id = rcl_get_group_id_by_post($this->post_id); $widget_options = rcl_get_group_option($group_id, 'widgets_options'); if (isset($widget_options['group-public-form-widget'])) { $this->type_editor = $widget_options['group-public-form-widget']['type_form']; } } else { if (!current_user_can('edit_post', $this->post_id)) { $this->can_edit = false; } } $form_id = get_post_meta($this->post_id, 'publicform-id', 1); if ($form_id) { $this->form_id = $form_id; } } $taxs = array(); $taxs = apply_filters('taxonomy_public_form_rcl', $taxs); if (isset($rcl_options['accept-' . $this->post_type])) { $this->accept = $rcl_options['accept-' . $this->post_type]; } $formData = (object) array('form_id' => $this->form_id, 'post_id' => $this->post_id, 'post_type' => $this->post_type, 'id_upload' => $this->id_upload, 'terms' => $this->terms, 'accept' => $this->accept, 'type_editor' => $this->type_editor, 'wp_editor' => $this->wp_editor, 'taxonomy' => $taxs); if ($this->user_can()) { rcl_fileapi_scripts(); rcl_fileupload_scripts(); } if ($this->post_id) { add_filter('after_public_form_rcl', array(&$this, 'delete_button'), 10, 2); } }
function rcl_apply_group_request() { global $rcl_group, $user_ID; $user_id = intval($_POST['user_id']); $apply = intval($_POST['apply']); $group_id = intval($_POST['group_id']); $rcl_group = rcl_get_group($group_id); if ($rcl_group->admin_id != $user_ID) { return false; } $requests = rcl_get_group_option($group_id, 'requests_group_access'); $key = array_search($user_id, $requests); if (!$requests || false === $key) { return false; } unset($requests[$key]); if ($apply) { $subject = __('Request access to the group approved!', 'wp-recall'); $textmail = ' <h3>Добро пожаловать в группу "' . $rcl_group->name . '"!</h3> <p>Поздравляем, ваш запрос на доступ к приватной группе на сайте "' . get_bloginfo('name') . '" был одобрен.</p> <p>Теперь вы можете принимать участие в жизни этой группы как полноценный ее участник.</p> <p>Вы можете перейти в группу прямо сейчас, перейдя по ссылке:</p> <p>' . get_term_link((int) $group_id, 'groups') . '</p>'; rcl_group_add_user($user_id, $group_id); $log['result'] = '<span class="success">' . __('The request was accepted', 'wp-recall') . '</span>'; } else { $log['result'] = '<span class="error">' . __('Request rejected', 'wp-recall') . '</span>'; $subject = __('The request to access the group rejected.', 'wp-recall'); $textmail = ' <p>Сожалеем, но ваш запрос на доступ к приватной группе "' . $rcl_group->name . '" на сайте "' . get_bloginfo('name') . '" был отклонен ее админом.</p>'; } $user_email = get_the_author_meta('user_email', $user_id); rcl_mail($user_email, $subject, $textmail); rcl_update_group_option($group_id, 'requests_group_access', $requests); $log['user_id'] = $user_id; echo json_encode($log); exit; }
function manage_widgets($group_id) { global $rcl_group_widgets, $rcl_group_area, $user_ID; $rcl_group_widgets = apply_filters('rcl_group_widgets', $rcl_group_widgets); $content = '<div id="widgets-options">'; $content .= '<form method="post">' . '<input type="submit" class="recall-button" name="group-submit" value="' . __('Save changes', 'wp-recall') . '">'; $zones = array(); if ($rcl_group_area[0]['id'] != 'unuses') { array_unshift($rcl_group_area, array('id' => 'unuses', 'name' => __('Unused', 'wp-recall'))); } //print_r($rcl_group_area);exit; $widgets_options = rcl_get_group_option($group_id, 'widgets_options'); foreach ($rcl_group_area as $zone) { $zones[] = '#' . $zone['id'] . '-widgets'; $content .= '<div id="' . $zone['id'] . '-zone" class="widgets-zone">'; $content .= '<input type="hidden" name="data[][content]" value="' . $zone['id'] . '">'; $content .= '<span class="zone-name">' . $zone['name'] . '</span>'; $content .= '<ul id="' . $zone['id'] . '-widgets" class="sortable-connected">'; foreach ($rcl_group_widgets as $widget) { if ($widget->widget_place != $zone['id']) { continue; } $options = false; $obj = new $widget->class(); $this->widget = $obj->widget; $this->widget['options'] = $widgets_options[$widget->widget_id]; $method = 'options'; if (method_exists($obj, $method)) { ob_start(); $obj->{$method}($this->widget['options']); $options = ob_get_contents(); ob_end_clean(); } $content .= '<li id="' . $widget->widget_id . '-widget" class="widget-box">'; $content .= '<input type="hidden" name="data[][widget][' . $this->widget['widget_id'] . '][id]" value="' . $widget->widget_id . '">'; if ($options) { $content .= '<span class="widget-name" onclick="rcl_more_view(this); return false;"><i class="fa fa-plus-square-o"></i>' . $widget->widget_title . '</span>'; } else { $content .= '<span class="widget-name">' . $widget->widget_title . '</span>'; } if ($options) { $content .= '<div class="widget-options" style="display:none;">' . $options . '</div>'; } $content .= '</li>'; } $content .= '</ul>'; $content .= '</div>'; } $content .= '<input type="hidden" name="group-action" value="update-widgets">' . wp_nonce_field('group-action-' . $user_ID, '_wpnonce', true, false); $content .= '</form>'; $content .= '</div>' . '<script> jQuery(function() { jQuery( "' . implode(',', $zones) . '" ).sortable({ connectWith: ".sortable-connected", placeholder: "ui-state-highlight", distance: 3, cursor: "move", forceHelperSize: true }); }); </script>'; return $content; }
function rcl_group_avatar_upload() { require_once ABSPATH . "wp-admin" . '/includes/image.php'; require_once ABSPATH . "wp-admin" . '/includes/file.php'; require_once ABSPATH . "wp-admin" . '/includes/media.php'; global $user_ID, $rcl_options, $rcl_avatar_sizes; if (!$user_ID) { return false; } $upload = array(); $group_id = $_POST['group_id']; $maxsize = $rcl_options['avatar_weight'] ? $rcl_options['avatar_weight'] : ($maxsize = 2); $tmpname = current_time('timestamp') . '.jpg'; //print_r($_FILES['uploadfile']);exit; if ($_FILES['uploadfile']) { foreach ($_FILES['uploadfile'] as $key => $data) { $upload['file'][$key] = $data; } } $filename = $upload['file']['name']; $mime = explode('/', $upload['file']['type']); $tps = explode('.', $upload['file']['name']); $cnt = count($tps); if ($cnt > 2) { $type = $mime[$cnt - 1]; $filename = str_replace('.', '', $filename); $filename = str_replace($type, '', $filename) . '.' . $type; } $filename = str_replace(' ', '', $filename); $mb = $upload['file']['size'] / 1024 / 1024; if ($mb > $maxsize) { $res['error'] = __('Size over', 'wp-recall'); echo json_encode($res); exit; } $ext = explode('.', $filename); if ($mime[0] != 'image') { $res['error'] = __('The file is not an image', 'wp-recall'); echo json_encode($res); exit; } $image = wp_handle_upload($_FILES['uploadfile'], array('test_form' => FALSE)); if ($image['file']) { if ($avatar_id = rcl_get_group_option($group_id, 'avatar_id')) { wp_delete_post($avatar_id, true); } $attachment = array('post_mime_type' => $image['type'], 'post_title' => 'image_group_' . $group_id, 'post_content' => $image['url'], 'guid' => $image['url'], 'post_parent' => '', 'post_status' => 'inherit'); $imade_id = wp_insert_attachment($attachment, $image['file']); $attach_data = wp_generate_attachment_metadata($imade_id, $image['file']); wp_update_attachment_metadata($imade_id, $attach_data); rcl_update_group_option($group_id, 'avatar_id', $imade_id); } else { $res['error'] = 'Ошибка загрузки!'; echo json_encode($res); exit; } $res['avatar_url'] = $image['url']; $res['success'] = __('Avatar has successfully loaded', 'wp-recall'); echo json_encode($res); exit; }
function rcl_group_admin_panel() { global $rcl_group; $admins_buttons = array(array('callback' => 'rcl_get_group_options', 'name' => __('Primary options', 'wp-recall')), array('callback' => 'rcl_get_group_widgets', 'name' => __('Widgets manage', 'wp-recall'))); if ($rcl_group->group_status == 'closed') { $requests = rcl_get_group_option($rcl_group->term_id, 'requests_group_access'); //if($requests) $admins_buttons[] = array('callback' => 'rcl_get_group_requests_content', 'name' => __('Requests for access', 'wp-recall') . ' - ' . count($requests)); } $admins_buttons = apply_filters('rcl_group_admin_panel', $admins_buttons); foreach ($admins_buttons as $button) { $buttons[] = '<li class="admin-button">' . rcl_get_group_link($button['callback'], $button['name']) . '</li>'; } $panel = '<div id="group-admin-panel">' . '<span class="title-panel"><i class="fa fa-cogs"></i>' . __('Administration', 'wp-recall') . '</span>' . '<ul>' . implode('', $buttons) . '</ul>' . '</div>'; echo $panel; }