/** * @param null $tab * @param UserTable $user * @param int $ui * @param array $postdata */ public function getCBpluginComponent($tab, $user, $ui, $postdata) { global $_CB_framework, $_PLUGINS, $_CB_PMS; cbSpoofCheck('plugin'); $id = $this->input('id', null, GetterInterface::INT); $user = CBuser::getMyUserDataInstance(); if (!$id) { cbRedirect($_CB_framework->userProfileUrl($user->get('id'), false, 'getmypmsproTab'), CBTxt::T('SEND_PMS_MISSING_TO_USER', 'Private message failed to send! Error: Missing to user'), 'error'); } $profileUrl = $_CB_framework->userProfileUrl($id, false, 'getmypmsproTab'); if (!$user->get('id')) { cbRedirect($profileUrl, CBTxt::T('Not authorized.'), 'error'); } if ($id == $user->get('id')) { cbRedirect($profileUrl, CBTxt::T('SEND_PMS_ERROR_SELF', 'Private message failed to send! Error: You can not send a private message to your self'), 'error'); } $tab = new TabTable(); $tab->load(array('pluginclass' => 'getmypmsproTab')); if (!($tab->enabled && Application::MyUser()->canViewAccessLevel($tab->viewaccesslevel))) { cbRedirect($profileUrl, CBTxt::T('Not authorized.'), 'error'); } $subject = $this->input('subject', null, GetterInterface::STRING); $message = $this->input('message', null, GetterInterface::STRING); $send = $_CB_PMS->sendPMSMSG($id, $user->get('id'), $subject, $message, false); if (is_array($send) && count($send) > 0) { $result = $send[0]; } else { $result = false; } if ($result) { cbRedirect($profileUrl, CBTxt::T('SEND_PMS_SUCCESS', 'Private message sent successfully!')); } else { cbRedirect($profileUrl, $_PLUGINS->getErrorMSG(), 'error'); } }
/** * @param TabTable $tab Current tab * @param UserTable $user Current user * @param int $ui 1 front, 2 admin UI * @param array $postdata Raw unfiltred POST data * @return string HTML */ public function getCBpluginComponent($tab, $user, $ui, $postdata) { global $_CB_framework; outputCbJs(1); outputCbTemplate(1); $plugin = cbblogsClass::getPlugin(); $model = cbblogsClass::getModel(); $action = $this->input('action', null, GetterInterface::STRING); $function = $this->input('func', null, GetterInterface::STRING); $id = $this->input('id', null, GetterInterface::INT); $user = CBuser::getUserDataInstance($_CB_framework->myId()); $tab = new TabTable(); $tab->load(array('pluginid' => (int) $plugin->id)); $profileUrl = $_CB_framework->userProfileUrl($user->get('id'), false, 'cbblogsTab'); if (!($tab->enabled && Application::MyUser()->canViewAccessLevel($tab->viewaccesslevel))) { cbRedirect($profileUrl, CBTxt::T('Not authorized.'), 'error'); } ob_start(); switch ($action) { case 'blogs': switch ($function) { case 'new': $this->showBlogEdit(null, $user, $model, $plugin); break; case 'edit': $this->showBlogEdit($id, $user, $model, $plugin); break; case 'save': cbSpoofCheck('plugin'); $this->saveBlogEdit($id, $user, $model, $plugin); break; case 'publish': $this->stateBlog(1, $id, $user, $model, $plugin); break; case 'unpublish': $this->stateBlog(0, $id, $user, $model, $plugin); break; case 'delete': $this->deleteBlog($id, $user, $model, $plugin); break; case 'show': default: if ($model->type != 2) { cbRedirect(cbblogsModel::getUrl((int) $id, false)); } else { $this->showBlog($id, $user, $model, $plugin); } break; } break; default: cbRedirect($profileUrl, CBTxt::T('Not authorized.'), 'error'); break; } $html = ob_get_contents(); ob_end_clean(); $class = $plugin->params->get('general_class', null); $return = '<div id="cbBlogs" class="cbBlogs' . ($class ? ' ' . htmlspecialchars($class) : null) . '">' . '<div id="cbBlogsInner" class="cbBlogsInner">' . $html . '</div>' . '</div>'; echo $return; }
/** * @param null $tab * @param UserTable $user * @param int $ui * @param array $postdata */ public function getCBpluginComponent( $tab, $user, $ui, $postdata ) { global $_CB_framework; outputCbJs( 1 ); outputCbTemplate( 1 ); $action = $this->input( 'action', null, GetterInterface::STRING ); $function = $this->input( 'func', null, GetterInterface::STRING ); $id = $this->input( 'id', null, GetterInterface::INT ); $user = CBuser::getMyUserDataInstance(); $tab = new TabTable(); $tab->load( array( 'pluginclass' => 'cbinvitesTab' ) ); $profileUrl = $_CB_framework->userProfileUrl( $user->get( 'id' ), false, 'cbinvitesTab' ); if ( ! ( $tab->enabled && Application::MyUser()->canViewAccessLevel( $tab->viewaccesslevel ) ) ) { cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' ); } ob_start(); switch ( $action ) { case 'preparaty': switch ( $function ) { case 'delete': $this->deletePreparaty( $id, $user ); break; } break; default: cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' ); break; } $html = ob_get_contents(); ob_end_clean(); $class = $this->params->get( 'general_class', null ); $return = '<div id="cbInvites" class="cbInvites' . ( $class ? ' ' . htmlspecialchars( $class ) : null ) . '">' . '<div id="cbInvitesInner" class="cbInvitesInner">' . $html . '</div>' . '</div>'; echo $return; }
/** * Commented CBT calls for language parser pickup: Moved to cb.core.php so they get picked-up in front-end language file and not in backend one. */ function loadSampleData() { global $_CB_Backend_Title; @set_time_limit(240); $_CB_Backend_Title = array(0 => array('fa fa-wrench', CBTxt::T('TOOLS_SAMPLE_DATA_TITLE', 'CB Tools: Sample Data: Results'))); $return = null; $affected = false; $tab = new TabTable(); $tab->load(array('title' => '_UE_ADDITIONAL_INFO_HEADER')); if (!$tab->tabid) { $affected = true; $tab->set('title', '_UE_ADDITIONAL_INFO_HEADER'); $tab->set('displaytype', 'menunested'); $tab->set('position', 'canvas_main_middle'); $tab->set('viewaccesslevel', 1); $tab->set('enabled', 1); $tab->set('ordering', 1); if ($tab->getError() || !$tab->store()) { $return .= '<div class="form-group cb_form_line clearfix text-danger">' . CBTxt::T('TOOLS_SAMPLE_DATA_TAB_NOT_OK', 'Tab [title] failed to add. Error: [error]', array('[title]' => $tab->get('title'), '[error]' => $tab->getError())) . '</div>'; } } if ($affected) { $return .= '<div class="form-group cb_form_line clearfix text-success">' . CBTxt::T('TOOLS_SAMPLE_DATA_TAB_OK', 'Tab Added Successfully!') . '</div>'; } $affected = false; $fields = array('cb_website' => array('title' => '_UE_Website', 'type' => 'webaddress', 'registration' => 0, 'ordering' => 1), 'cb_location' => array('title' => '_UE_Location', 'type' => 'text', 'maxlength' => 50, 'size' => 25, 'registration' => 0, 'ordering' => 2), 'cb_occupation' => array('title' => '_UE_Occupation', 'type' => 'text', 'registration' => 0, 'ordering' => 3), 'cb_interests' => array('title' => '_UE_Interests', 'type' => 'text', 'registration' => 0, 'ordering' => 4), 'cb_company' => array('title' => '_UE_Company', 'type' => 'text', 'ordering' => 5), 'cb_city' => array('title' => '_UE_City', 'type' => 'text', 'ordering' => 6), 'cb_state' => array('title' => '_UE_State', 'type' => 'text', 'maxlength' => 10, 'size' => 4, 'ordering' => 7), 'cb_zipcode' => array('title' => '_UE_ZipCode', 'type' => 'text', 'ordering' => 8), 'cb_country' => array('title' => '_UE_Country', 'type' => 'text', 'ordering' => 9), 'cb_address' => array('title' => '_UE_Address', 'type' => 'text', 'ordering' => 10), 'cb_phone' => array('title' => '_UE_PHONE', 'type' => 'text', 'ordering' => 11), 'cb_fax' => array('title' => '_UE_FAX', 'type' => 'text', 'ordering' => 12)); foreach ($fields as $fieldName => $fieldSettings) { $field = new FieldTable(); $field->load(array('name' => $fieldName)); if (!$field->fieldid) { $affected = true; $field->set('name', $fieldName); $field->set('registration', 1); $field->set('profile', 1); $field->set('edit', 1); $field->set('published', 1); foreach ($fieldSettings as $column => $value) { $field->set($column, $value); } $field->set('tabid', $tab->tabid); $field->set('pluginid', 1); if ($field->getError() || !$field->store()) { $return .= '<div class="form-group cb_form_line clearfix text-danger">' . CBTxt::T('TOOLS_SAMPLE_DATA_FIELD_NOT_OK', 'Field [name] failed to add. Error: [error]', array('[name]' => $field->get('name'), '[error]' => $field->getError())) . '</div>'; } } } if ($affected) { $return .= '<div class="form-group cb_form_line clearfix text-success">' . CBTxt::T('TOOLS_SAMPLE_DATA_FIELD_OK', 'Fields Added Successfully!') . '</div>'; } $affected = false; $list = new ListTable(); $list->load(array('title' => 'Members List')); if (!$list->listid) { $affected = true; $list->set('title', 'Members List'); $list->set('viewaccesslevel', 1); $list->set('usergroupids', '1|*|6|*|7|*|2|*|3|*|4|*|5|*|8'); $list->set('default', 1); $list->set('published', 1); $list->set('ordering', 1); $listParams = new Registry(); $listParams->set('sort_mode', '0'); $listParams->set('basic_sort', array(array('column' => 'username', 'direction' => 'ASC'))); $listParams->set('columns', array(array('title' => 'User', 'size' => '3', 'fields' => array(array('field' => '17', 'display' => '4'), array('field' => '29', 'display' => '4'), array('field' => '42', 'display' => '4'), array('field' => '26', 'display' => '4'))), array('title' => 'Info', 'size' => '9', 'fields' => array(array('field' => '27', 'display' => '1'), array('field' => '49', 'display' => '1'), array('field' => '28', 'display' => '1'))))); $listParams->set('list_grid_layout', '1'); $list->set('params', $listParams->asJson()); if ($list->getError() || !$list->store()) { $return .= '<div class="form-group cb_form_line clearfix text-danger">' . CBTxt::T('TOOLS_SAMPLE_DATA_LIST_NOT_OK', 'List [title] failed to add. Error: [error]', array('[title]' => $list->get('title'), '[error]' => $tab->getError())) . '</div>'; } } if ($affected) { $return .= '<div class="form-group cb_form_line clearfix text-success">' . CBTxt::T('TOOLS_SAMPLE_DATA_LIST_OK', 'List Added Successfully!') . '</div>'; } if (!$return) { $return .= '<div class="form-group cb_form_line clearfix">' . CBTxt::T('TOOLS_SAMPLE_DATA_ALREADY_CONFIGURED', 'Sample Data is already loaded!') . '</div>'; } echo $return; }
function plug_cbgroupjive_install() { global $_CB_database, $_PLUGINS; // Uninstall the old integrations to avoid conflicts: $integrations = array( 'cbgroupjiveabout', 'cbgroupjiveevents', 'cbgroupjivefile', 'cbgroupjiveforums', 'cbgroupjivephoto', 'cbgroupjivevideo', 'cbgroupjivewall', 'cbgroupjiveauto' ); foreach ( $integrations as $integration ) { $plugin = new PluginTable(); $plugin->load( array( 'element' => $integration ) ); if ( $plugin->get( 'id' ) && ( ! is_dir( $_PLUGINS->getPluginPath( $plugin ) . '/xml' ) ) ) { $plugin->delete(); } } // Migrate categories: $table = '#__groupjive_categories'; $fields = $_CB_database->getTableFields( $table ); $migrate = false; if ( isset( $fields[$table]['parent'] ) ) { $migrate = true; $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_categories' ); $_CB_database->setQuery( $query ); $categories = $_CB_database->loadObjectList( null, '\CBLib\Database\Table\Table', array( $_CB_database, '#__groupjive_categories', 'id' ) ); /** @var $categories Table[] */ foreach ( $categories as $category ) { $category->set( 'access', ( $category->get( 'access' ) == -2 ? 1 : ( $category->get( 'access' ) == -1 ? 2 : Application::CmsPermissions()->convertOldGroupToViewAccessLevel( $category->get( 'access' ), 'CB GroupJive: Category Access - ' . (int) $category->get( 'id' ) ) ) ) ); $category->set( 'create_access', ( ! $category->get( 'create' ) ? -1 : ( $category->get( 'create_access' ) == -1 ? 2 : Application::CmsPermissions()->convertOldGroupToViewAccessLevel( $category->get( 'create_access' ), 'CB GroupJive: Category Create Access - ' . (int) $category->get( 'id' ) ) ) ) ); $categoryParams = new Registry( $category->get( 'params' ) ); // CB GroupJive Forums: $categoryParams->set( 'forums', $categoryParams->get( 'forum_show' ) ); $category->set( 'params', $categoryParams->asJson() ); $category->store(); } // Remove the old columns: $_CB_database->dropColumn( $table, 'parent' ); $_CB_database->dropColumn( $table, 'create' ); $_CB_database->dropColumn( $table, 'nested' ); $_CB_database->dropColumn( $table, 'nested_access' ); } // Migrate groups: $table = '#__groupjive_groups'; $fields = $_CB_database->getTableFields( $table ); if ( isset( $fields[$table]['parent'] ) ) { $migrate = true; $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_groups' ); $_CB_database->setQuery( $query ); $groups = $_CB_database->loadObjectList( null, '\CBLib\Database\Table\Table', array( $_CB_database, '#__groupjive_groups', 'id' ) ); /** @var $groups Table[] */ foreach ( $groups as $group ) { $groupParams = new Registry( $group->get( 'params' ) ); // Core: $groupParams->set( 'invites', ( $group->get( 'invite' ) > 0 ? 0 : 1 ) ); // CB GroupJive Events: $groupParams->set( 'events', ( $groupParams->get( 'events_approve' ) ? 2 : $groupParams->get( 'events_show' ) ) ); // CB GroupJive File: $groupParams->set( 'file', ( $groupParams->get( 'file_approve' ) ? 2 : $groupParams->get( 'file_show' ) ) ); // CB GroupJive Forums: $groupParams->set( 'forums', $groupParams->get( 'forum_show' ) ); // CB GroupJive Photo: $groupParams->set( 'photo', ( $groupParams->get( 'photo_approve' ) ? 2 : $groupParams->get( 'photo_show' ) ) ); // CB GroupJive Video: $groupParams->set( 'video', ( $groupParams->get( 'video_approve' ) ? 2 : $groupParams->get( 'video_show' ) ) ); // CB GroupJive Wall: $groupParams->set( 'wall', ( $groupParams->get( 'wall_approve' ) ? 2 : $groupParams->get( 'wall_show' ) ) ); $group->set( 'params', $groupParams->asJson() ); $group->store(); } // Remove the old columns: $_CB_database->dropColumn( $table, 'parent' ); $_CB_database->dropColumn( $table, 'access' ); $_CB_database->dropColumn( $table, 'invite' ); $_CB_database->dropColumn( $table, 'users' ); $_CB_database->dropColumn( $table, 'nested' ); $_CB_database->dropColumn( $table, 'nested_access' ); } // Migrate notifications: $table = '#__groupjive_notifications'; $fields = $_CB_database->getTableFields( $table ); if ( isset( $fields[$table]['type'] ) ) { $migrate = true; // Delete notification types no longer supported: $query = 'DELETE' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_notifications' ) . "\n WHERE " . $_CB_database->NameQuote( 'type' ) . " != " . $_CB_database->Quote( 'group' ); $_CB_database->setQuery( $query ); $_CB_database->query(); // Migration notification parameters: $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_notifications' ); $_CB_database->setQuery( $query ); $notifications = $_CB_database->loadObjectList( null, '\CBLib\Database\Table\Table', array( $_CB_database, '#__groupjive_notifications', 'id' ) ); /** @var $notifications Table[] */ foreach ( $notifications as $notification ) { if ( ( $notification->get( 'type' ) == 'group' ) && $notification->get( 'item' ) ) { $notification->set( 'group', (int) $notification->get( 'item' ) ); $notificationParams = new Registry( $notification->get( 'params' ) ); // Core: $notificationParams->set( 'user_join', $notificationParams->get( 'group_userjoin' ) ); $notificationParams->set( 'user_leave', $notificationParams->get( 'group_userleave' ) ); $notificationParams->set( 'user_approve', $notificationParams->get( 'group_userapprove' ) ); $notificationParams->set( 'invite_accept', $notificationParams->get( 'group_inviteaccept' ) ); // CB GroupJive Events: $notificationParams->set( 'event_new', $notificationParams->get( 'group_eventnew' ) ); $notificationParams->set( 'event_approve', $notificationParams->get( 'group_eventapprove' ) ); $notificationParams->set( 'event_attend', $notificationParams->get( 'group_eventyes' ) ); $notificationParams->set( 'event_unattend', $notificationParams->get( 'group_eventno' ) ); // CB GroupJive File: $notificationParams->set( 'file_new', $notificationParams->get( 'group_filenew' ) ); $notificationParams->set( 'file_approve', $notificationParams->get( 'group_fileapprove' ) ); // CB GroupJive Photo: $notificationParams->set( 'photo_new', $notificationParams->get( 'group_photonew' ) ); $notificationParams->set( 'photo_approve', $notificationParams->get( 'group_photoapprove' ) ); // CB GroupJive Video: $notificationParams->set( 'video_new', $notificationParams->get( 'group_videonew' ) ); $notificationParams->set( 'video_approve', $notificationParams->get( 'group_videoapprove' ) ); // CB GroupJive Wall: $notificationParams->set( 'wall_new', $notificationParams->get( 'group_wallnew' ) ); $notificationParams->set( 'wall_approve', $notificationParams->get( 'group_wallapprove' ) ); $notificationParams->set( 'wall_reply', $notificationParams->get( 'group_wallreply' ) ); $notification->set( 'params', $notificationParams->asJson() ); $notification->store(); } } // Remove the old columns: $_CB_database->dropColumn( $table, 'type' ); $_CB_database->dropColumn( $table, 'item' ); } if ( $migrate ) { // Migrate global parameters: $plugin = new PluginTable(); $plugin->load( array( 'element' => 'cbgroupjive' ) ); $pluginParams = new Registry( $plugin->get( 'params' ) ); // Logos: $pluginParams->set( 'logo_max_size', $pluginParams->get( 'logo_size' ) ); $pluginParams->set( 'logo_image_width', $pluginParams->get( 'logo_width' ) ); $pluginParams->set( 'logo_image_height', $pluginParams->get( 'logo_height' ) ); $pluginParams->set( 'logo_thumbnail_width', $pluginParams->get( 'logo_thumbwidth' ) ); $pluginParams->set( 'logo_thumbnail_height', $pluginParams->get( 'logo_thumbheight' ) ); // Notifications: $pluginParams->set( 'notifications', $pluginParams->get( 'general_notifications' ) ); $pluginParams->set( 'notifications_notifyby', ( $pluginParams->get( 'general_notifyby' ) < 4 ? 2 : 1 ) ); $pluginParams->set( 'notifications_default_user_join', $pluginParams->get( 'notifications_group_userjoin' ) ); $pluginParams->set( 'notifications_default_user_leave', $pluginParams->get( 'notifications_group_userleave' ) ); $pluginParams->set( 'notifications_default_user_approve', $pluginParams->get( 'notifications_group_userapprove' ) ); $pluginParams->set( 'notifications_default_invite_accept', $pluginParams->get( 'notifications_group_inviteaccept' ) ); // Categories: $pluginParams->set( 'categories_paging', $pluginParams->get( 'overview_paging' ) ); $pluginParams->set( 'categories_limit', $pluginParams->get( 'overview_limit' ) ); $pluginParams->set( 'categories_search', $pluginParams->get( 'overview_search' ) ); switch( (int) $pluginParams->get( 'overview_orderby' ) ) { case 7: $orderBy = 5; break; case 8: $orderBy = 6; break; case 5: $orderBy = 3; break; case 6: $orderBy = 4; break; case 1: case 2: $orderBy = (int) $pluginParams->get( 'overview_orderby' ); break; case 3: case 4: case 9: case 10: default: $orderBy = 1; break; } $pluginParams->set( 'categories_orderby', $orderBy ); $pluginParams->set( 'categories_groups_paging', $pluginParams->get( 'category_groups_paging' ) ); $pluginParams->set( 'categories_groups_limit', $pluginParams->get( 'category_groups_limit' ) ); $pluginParams->set( 'categories_groups_search', $pluginParams->get( 'category_groups_search' ) ); $pluginParams->set( 'categories_groups_orderby', ( $pluginParams->get( 'category_groups_orderby' ) > 8 ? 4 : $pluginParams->get( 'category_groups_orderby' ) ) ); // Groups: $pluginParams->set( 'groups_create_access', ( ! $pluginParams->get( 'group_create' ) ? -1 : ( $pluginParams->get( 'group_create_access' ) == -1 ? 2 : Application::CmsPermissions()->convertOldGroupToViewAccessLevel( $pluginParams->get( 'group_create_access' ), 'CB GroupJive: Groups Create Access' ) ) ) ); $pluginParams->set( 'groups_create_limit', $pluginParams->get( 'group_limit' ) ); $pluginParams->set( 'groups_create_approval', $pluginParams->get( 'group_approve' ) ); $pluginParams->set( 'groups_create_captcha', $pluginParams->get( 'group_captcha' ) ); $pluginParams->set( 'groups_message', $pluginParams->get( 'group_message' ) ); $pluginParams->set( 'groups_message_captcha', $pluginParams->get( 'group_message_captcha' ) ); $pluginParams->set( 'groups_users_paging', $pluginParams->get( 'group_users_paging' ) ); $pluginParams->set( 'groups_users_limit', $pluginParams->get( 'group_users_limit' ) ); $pluginParams->set( 'groups_users_search', $pluginParams->get( 'group_users_search' ) ); $pluginParams->set( 'groups_invites_display', $pluginParams->get( 'group_invites_display' ) ); $pluginParams->set( 'groups_invites_by', $pluginParams->get( 'group_invites_by' ) ); $pluginParams->set( 'groups_invites_list', $pluginParams->get( 'group_invites_list' ) ); $pluginParams->set( 'groups_invites_accept', $pluginParams->get( 'group_invites_accept' ) ); $pluginParams->set( 'groups_invites_captcha', $pluginParams->get( 'group_invites_captcha' ) ); $pluginParams->set( 'groups_invites_paging', $pluginParams->get( 'group_invites_paging' ) ); $pluginParams->set( 'groups_invites_limit', $pluginParams->get( 'group_invites_limit' ) ); $pluginParams->set( 'groups_invites_search', $pluginParams->get( 'group_invites_search' ) ); $pluginParams->set( 'groups_paging', $pluginParams->get( 'group_all_paging' ) ); $pluginParams->set( 'groups_limit', $pluginParams->get( 'group_all_limit' ) ); $pluginParams->set( 'groups_search', $pluginParams->get( 'group_all_search' ) ); $pluginParams->set( 'groups_orderby', ( $pluginParams->get( 'group_all_orderby' ) > 8 ? 4 : $pluginParams->get( 'group_all_orderby' ) ) ); $plugin->set( 'params', $pluginParams->asJson() ); $plugin->store(); // Migrate the old auto fields to core GJ: $query = 'UPDATE '. $_CB_database->NameQuote( '#__comprofiler_fields' ) . "\n SET " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'groupautojoin' ) . ', ' . $_CB_database->NameQuote( 'pluginid' ) . ' = ' . (int) $plugin->get( 'id' ) . "\n WHERE " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'cbgjautojoin' ); $_CB_database->setQuery( $query ); $_CB_database->query(); // Migrate tab parameters: $tab = new TabTable(); $tab->load( array( 'pluginclass' => 'cbgjTab' ) ); $tabParams = new Registry( $tab->get( 'params' ) ); $tabParams->set( 'tab_paging', $pluginParams->get( 'group_tab_paging' ) ); $tabParams->set( 'tab_limit', $pluginParams->get( 'group_tab_limit' ) ); $tabParams->set( 'tab_search', $pluginParams->get( 'group_tab_search' ) ); $tabParams->set( 'tab_orderby', ( $pluginParams->get( 'group_tab_orderby' ) > 8 ? 4 : $pluginParams->get( 'group_tab_orderby' ) ) ); $tab->set( 'params', $tabParams->asJson() ); $tab->store(); } // Migrate gj auto to cb auto actions if possible: $table = '#__groupjive_plugin_auto'; if ( $_CB_database->getTableStatus( $table ) ) { $fields = $_CB_database->getTableFields( $table ); if ( isset( $fields[$table]['trigger'] ) ) { $autoActions = new PluginTable(); $autoActions->load( array( 'element' => 'cbautoactions' ) ); if ( $autoActions->get( 'id' ) ) { $table = '#__comprofiler_plugin_autoactions'; $fields = $_CB_database->getTableFields( $table ); if ( ! isset( $fields[$table]['conditions'] ) ) { return; } $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_auto' ); $_CB_database->setQuery( $query ); $autos = $_CB_database->loadObjectList( null, '\CBLib\Database\Table\Table', array( $_CB_database, '#__groupjive_plugin_auto', 'id' ) ); /** @var $autos Table[] */ foreach ( $autos as $auto ) { $oldParams = new Registry( $auto->get( 'params' ) ); if ( $oldParams->get( 'migrated' ) ) { continue; } $newParams = new Registry(); $newConditions = null; if ( $auto->get( 'field' ) ) { $fields = new Registry( $auto->get( 'field' ) ); $operators = new Registry( $auto->get( 'operator' ) ); $values = new Registry( $auto->get( 'value' ) ); $conditionals = count( $fields ); if ( $conditionals ) { $conditions = array(); for ( $i = 0, $n = $conditionals; $i < $n; $i++ ) { $field = $fields->get( "field$i" ); $operator = $operators->get( "operator$i" ); $value = $values->get( "value$i" ); if ( $operator ) { $conditions[] = array( 'field' => $field, 'operator' => $operator, 'value' => $value, 'translate' => 0 ); } } if ( $conditions ) { $newConditionals = new Registry( $conditions ); $newConditions = $newConditionals->asJson(); } } } $mode = $oldParams->get( 'auto' ); $join = array( 'mode' => $mode, 'groups' => $oldParams->get( 'groups' ), 'status' => $oldParams->get( 'status' ), 'name' => ( $mode == 2 ? $oldParams->get( 'grp_name' ) : $oldParams->get( 'cat_name' ) ), 'category' => $oldParams->get( 'category' ), 'category_name' => $oldParams->get( 'cat_name' ), 'category_parent' => $oldParams->get( 'cat_parent' ), 'category_types' => $oldParams->get( 'types' ), 'category_description' => $oldParams->get( 'cat_description' ), 'category_unique' => $oldParams->get( 'cat_unique' ), 'group_parent' => $oldParams->get( 'grp_parent' ), 'type' => $oldParams->get( 'type' ), 'parent' => $oldParams->get( 'cat_parent' ), 'types' => $oldParams->get( 'types' ), 'description' => ( $mode == 2 ? $oldParams->get( 'grp_description' ) : $oldParams->get( 'cat_description' ) ), 'owner' => ( $mode == 2 ? $oldParams->get( 'grp_owner' ) : $oldParams->get( 'cat_owner' ) ), 'unique' => ( $mode == 2 ? $oldParams->get( 'grp_unique' ) : $oldParams->get( 'cat_unique' ) ), 'autojoin' => $oldParams->get( 'grp_autojoin' ), 'group_status' => $oldParams->get( 'status' ) ); $newParams->set( 'groupjive', array( $join ) ); $newParams->set( 'exclude', $auto->get( 'exclude' ) ); $query = 'INSERT IGNORE INTO '. $_CB_database->NameQuote( '#__comprofiler_plugin_autoactions' ) . ' ( ' . $_CB_database->NameQuote( 'published' ) . ', ' . $_CB_database->NameQuote( 'title' ) . ', ' . $_CB_database->NameQuote( 'description' ) . ', ' . $_CB_database->NameQuote( 'type' ) . ', ' . $_CB_database->NameQuote( 'trigger' ) . ', ' . $_CB_database->NameQuote( 'object' ) . ', ' . $_CB_database->NameQuote( 'variable' ) . ', ' . $_CB_database->NameQuote( 'access' ) . ', ' . $_CB_database->NameQuote( 'conditions' ) . ', ' . $_CB_database->NameQuote( 'params' ) . ' ) VALUES ( ' . (int) $auto->get( 'published' ) . ', ' . $_CB_database->Quote( $auto->get( 'title' ) ) . ', ' . $_CB_database->Quote( $auto->get( 'description' ) ) . ', ' . $_CB_database->Quote( 'groupjive' ) . ', ' . $_CB_database->Quote( str_replace( ',', '|*|', $auto->get( 'trigger' ) ) ) . ', ' . $_CB_database->Quote( $auto->get( 'object' ) ) . ', ' . $_CB_database->Quote( $auto->get( 'variable' ) ) . ', ' . $_CB_database->Quote( $auto->get( 'access' ) ) . ', ' . $_CB_database->Quote( $newConditions ) . ', ' . $_CB_database->Quote( $newParams->asJson() ) . ' )'; $_CB_database->setQuery( $query ); $_CB_database->query(); $oldParams->set( 'migrated', true ); $auto->set( 'params', $oldParams->asJson() ); $auto->store(); } } } } }
/** * Installs a tab into database, finding already existing one if needed. * * @param int $pluginId Plugin id * @param SimpleXMLElement $tab XML element of Tab * @return int|boolean Id of tab or FALSE in case of error (error saved with $this->setError() ). */ function installTab($pluginId, $tab) { global $_CB_database; // Check to see if plugin tab already exists in db if (!$tab->attributes('tabid')) { if ($tab->attributes('class')) { $query = "SELECT tabid FROM #__comprofiler_tabs WHERE " . "pluginclass = " . $_CB_database->Quote($tab->attributes('class')); } else { $query = "SELECT tabid FROM #__comprofiler_tabs WHERE pluginid = " . (int) $pluginId . " AND pluginclass = ''"; } $_CB_database->setQuery($query); $tabId = $_CB_database->loadResult(); } else { $tabId = $tab->attributes('tabid'); } if ($tab->attributes('type') == 'existingSytemTab') { if ($tabId == null) { $this->setError(1, 'installTab error: existingSystemTab' . ': ' . $tab->attributes('class') . ' ' . 'not found' . '.'); return false; } } else { $row = new TabTable(); if ($tabId) { $row->load((int) $tabId); } if (!$row->tabid) { $row->title = $tab->attributes('name'); $row->description = trim($tab->attributes('description')); $row->ordering = 99; $row->position = $tab->attributes('position'); $row->displaytype = $tab->attributes('displaytype'); $row->ordering_register = $tab->attributes('ordering_register'); $row->enabled = $tab->attributes('enabled'); $row->viewaccesslevel = 1; $viewAccessLevelName = $tab->attributes('viewaccesslevel'); if ($viewAccessLevelName) { $accessLevels = Application::CmsPermissions()->getAllViewAccessLevels(); $viewAccessLevelId = array_search($viewAccessLevelName, $accessLevels); if ($viewAccessLevelId !== false) { $row->viewaccesslevel = $viewAccessLevelId; } } } $row->width = $tab->attributes('width'); $row->pluginclass = $tab->attributes('class'); $row->pluginid = $pluginId; $row->fields = $tab->attributes('fields'); $row->sys = $tab->attributes('sys'); if (!$row->store()) { $this->setError(1, 'SQL error' . ': ' . $row->getError()); return false; } $tabId = (int) $row->tabid; } return $tabId; }
/** * @param TabTable $tab Current tab * @param UserTable $user Current user * @param int $ui 1 front, 2 admin UI * @param array $postdata Raw unfiltred POST data * @return string HTML */ public function getCBpluginComponent( $tab, $user, $ui, $postdata ) { global $_CB_framework; $format = $this->input( 'format', null, GetterInterface::STRING ); if ( $format != 'raw' ) { outputCbJs( 1 ); outputCbTemplate( 1 ); } $action = $this->input( 'action', null, GetterInterface::STRING ); $function = $this->input( 'func', null, GetterInterface::STRING ); $type = $this->input( 'type', null, GetterInterface::STRING ); $id = (int) $this->input( 'id', null, GetterInterface::INT ); $userId = (int) $this->input( 'user', null, GetterInterface::INT ); $tabId = (int) $this->input( 'tab', null, GetterInterface::INT ); if ( ! $tabId ) { switch( $type ) { case 'photos': $tabId = 'cbgalleryTabPhotos'; break; case 'files': $tabId = 'cbgalleryTabFiles'; break; case 'videos': $tabId = 'cbgalleryTabVideos'; break; case 'music': $tabId = 'cbgalleryTabMusic'; break; } } $viewer = CBuser::getMyUserDataInstance(); if ( $userId ) { $user = CBuser::getUserDataInstance( (int) $userId ); } else { $user = CBuser::getMyUserDataInstance(); } $profileUrl = $_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, $tabId ); if ( ! in_array( $type, array( 'photos', 'files', 'videos', 'music' ) ) ) { if ( ( $action == 'items' ) && in_array( $function, array( 'download', 'preview', 'show' ) ) ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' ); } } $tab = new TabTable(); $tab->load( ( is_integer( $tabId ) ? $tabId : array( 'pluginclass' => $tabId ) ) ); if ( ! ( $tab->get( 'enabled' ) && Application::User( (int) $viewer->get( 'id' ) )->canViewAccessLevel( $tab->get( 'viewaccesslevel' ) ) ) ) { if ( ( $action == 'items' ) && in_array( $function, array( 'download', 'preview', 'show' ) ) ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' ); } } if ( ! ( $tab->params instanceof ParamsInterface ) ) { $tab->params = new Registry( $tab->params ); } if ( $format != 'raw' ) { ob_start(); } switch ( $action ) { case 'items': switch ( $function ) { case 'download': $this->outputItem( false, false, $id, $type, $tab, $user, $viewer ); break; case 'edit': $this->showItemEdit( $id, $type, $tab, $user, $viewer ); break; case 'new': $this->showItemEdit( null, $type, $tab, $user, $viewer ); break; case 'save': cbSpoofCheck( 'plugin' ); $this->saveItemEdit( $id, $type, $tab, $user, $viewer ); break; case 'publish': $this->stateItem( 1, $id, $type, $tab, $user, $viewer ); break; case 'unpublish': $this->stateItem( 0, $id, $type, $tab, $user, $viewer ); break; case 'delete': $this->deleteItem( $id, $type, $tab, $user, $viewer ); break; case 'preview': $this->outputItem( true, true, $id, $type, $tab, $user, $viewer ); break; case 'show': default: $this->outputItem( true, false, $id, $type, $tab, $user, $viewer ); break; } break; case 'folders': if ( ! $tab->params->get( 'tab_' . $type . '_folders', 1 ) ) { cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' ); } switch ( $function ) { case 'edit': $this->showFolderEdit( $id, $type, $tab, $user, $viewer ); break; case 'new': $this->showFolderEdit( null, $type, $tab, $user, $viewer ); break; case 'save': cbSpoofCheck( 'plugin' ); $this->saveFolderEdit( $id, $type, $tab, $user, $viewer ); break; case 'publish': $this->stateFolder( 1, $id, $type, $tab, $user, $viewer ); break; case 'unpublish': $this->stateFolder( 0, $id, $type, $tab, $user, $viewer ); break; case 'delete': $this->deleteFolder( $id, $type, $tab, $user, $viewer ); break; case 'show': default: $this->showFolder( $id, $type, $tab, $user, $viewer ); break; } break; default: cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); break; } if ( $format != 'raw' ) { $html = ob_get_contents(); ob_end_clean(); $class = $this->params->get( 'general_class', null ); $return = '<div id="cbGallery" class="cbGallery' . ( $class ? ' ' . htmlspecialchars( $class ) : null ) . '">' . '<div id="cbGalleryInner" class="cbGalleryInner">' . $html . '</div>' . '</div>'; echo $return; } }
function cbInstaller_install_plugins(&$return) { global $_CB_framework, $_CB_adminpath, $ueConfig; cbimport('cb.adminfilesystem'); cbimport('cb.installer'); $cbDatabase = \CBLib\Application\Application::Database(); // List of core plugins that are no longer core, but we just want to disable core status and not remove as they don't conflict: $deprecated = array('bootstrap', 'winclassic', 'webfx', 'osx', 'luna', 'dark', 'yanc', 'cb.mamblogtab', 'cb.simpleboardtab', 'cb.authortab'); foreach ($deprecated as $pluginElement) { $plugin = new PluginTable(); if ($plugin->load(array('element' => $pluginElement))) { $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_plugin') . "\n SET " . $cbDatabase->NameQuote('iscore') . " = 0" . "\n WHERE " . $cbDatabase->NameQuote('id') . " = " . (int) $plugin->id; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] failed to deprecate. Please run Tools > Check Community Builder Database to reattempt.', array('[element]' => $pluginElement)) . '</div>'; } $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_tabs') . "\n SET " . $cbDatabase->NameQuote('sys') . " = 0" . "\n WHERE " . $cbDatabase->NameQuote('pluginid') . " = " . (int) $plugin->id; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] tabs failed to deprecate. Please run Tools > Check Community Builder Database to reattempt.', array('[element]' => $pluginElement)) . '</div>'; } $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n SET " . $cbDatabase->NameQuote('sys') . " = 0" . "\n WHERE " . $cbDatabase->NameQuote('pluginid') . " = " . (int) $plugin->id; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] fields failed to deprecate. Please run Tools > Check Community Builder Database to reattempt.', array('[element]' => $pluginElement)) . '</div>'; } } } // List of plugins that conflict with the core that need to be removed (normally due to being merged into core): $conflicted = array('bootstrap', 'winclassic', 'webfx', 'osx', 'luna', 'dark', 'yanc', 'cb.mamblogtab', 'cb.authortab', 'cbvideofield', 'cb.filefield'); foreach ($conflicted as $pluginElement) { $plugin = new PluginTable(); if ($plugin->load(array('element' => $pluginElement))) { if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } } // Ensure Default template, CB Core, and language plugins are published as they are not allowed to be unpublished: $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_plugin') . "\n SET " . $cbDatabase->NameQuote('published') . " = 1" . "\n WHERE ( " . $cbDatabase->NameQuote('id') . " IN " . $cbDatabase->safeArrayOfIntegers(array(1, 7)) . ' OR ' . $cbDatabase->NameQuote('type') . ' = ' . $cbDatabase->quote('language') . ' )'; $cbDatabase->setQuery($query); $cbDatabase->query(); $pluginsFile = $_CB_adminpath . 'pluginsfiles.tgz'; // We need to ensure the core plugins archive actually exists before doing anything with it: if (!file_exists($pluginsFile)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Core plugins archive [path] missing.', array('[path]' => $pluginsFile)) . '</div>'; return false; } // We need zlib to unzip packages so lets check that it exists: if (!extension_loaded('zlib')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::T('Core plugins can not be installed as zlib is not installed.') . '</div>'; return false; } $installer = new cbInstallerPlugin(); // Uncompress the core plugins so we can install them: if (!$installer->upload($pluginsFile, true, false)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Core plugins can not be installed as uncompressing [path] failed.', array('[path]' => $pluginsFile)) . '</div>'; return false; } $adminFS = cbAdminFileSystem::getInstance(); $baseDir = $_CB_framework->getCfg('absolute_path') . '/components/com_comprofiler'; // Create the base plugin directory: if (!$adminFS->is_dir($baseDir . '/plugin')) { if (!$adminFS->mkdir($baseDir . '/plugin')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/index.html')) . '</div>'; return false; } } // Create the language template directory: if (!$adminFS->is_dir($baseDir . '/plugin/language')) { if (!$adminFS->mkdir($baseDir . '/plugin/language')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin/language')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/language/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/language/index.html')) . '</div>'; return false; } } // Create the template plugin directory: if (!$adminFS->is_dir($baseDir . '/plugin/templates')) { if (!$adminFS->mkdir($baseDir . '/plugin/templates')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin/templates')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/templates/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/templates/index.html')) . '</div>'; return false; } } // Create the user plugin directory: if (!$adminFS->is_dir($baseDir . '/plugin/user')) { if (!$adminFS->mkdir($baseDir . '/plugin/user')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create directory [path].', array('[path]' => $baseDir . '/plugin/user')) . '</div>'; return false; } if (!$adminFS->copy($baseDir . '/index.html', $baseDir . '/plugin/user/index.html')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Failed to create index [path].', array('[path]' => $baseDir . '/plugin/user/index.html')) . '</div>'; return false; } } // Install core plugins 1 by 1 silently: $installFrom = $installer->installDir(); $filesList = cbReadDirectory($installFrom, '.', true); foreach ($filesList as $file) { if (preg_match('/^.+\\.xml$/i', $file)) { $plgPath = $installFrom . (substr($installFrom, -1, 1) == '/' ? '' : '/') . $file; $plgXml = new SimpleXMLElement(trim(file_get_contents($plgPath))); if ($plgXml->getName() == 'cbinstall') { $plgDir = dirname($plgPath) . '/'; ob_start(); $plgInstaller = new cbInstallerPlugin(); $installed = $plgInstaller->install($plgDir); ob_end_clean(); if (!$installed) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Installing core plugin [plugin] failed with error [error].', array('[plugin]' => $plgInstaller->i_elementname ? $plgInstaller->i_elementname : $file, '[error]' => $plgInstaller->getError())) . '</div>'; return false; } } } } // Delete the expanded core plugins archive: $result = $adminFS->deldir(_cbPathName($installFrom . '/')); if ($result === false) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::T('Deleting expanded core plugins archive failed.') . '</div>'; } // Delete the core plugins archive: $result = $adminFS->unlink(_cbPathName($pluginsFile, false)); if ($result === false) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Deleting core plugins archive [path] failed.', array('[path]' => $pluginsFile)) . '</div>'; } // Sets the as ready so config can actually load this time: \CB\Application\CBConfig::setCbConfigReadyToLoad(true); // Load the config now that the tables exist encase they didn't during install: \CB\Application\CBConfig::loadLegacyCBueConfig(); // Migrate old file based configuration to database based configuration: $newConfig = null; if ($adminFS->file_exists($_CB_adminpath . 'ue_config.php')) { /** @noinspection PhpIncludeInspection */ include_once $_CB_adminpath . 'ue_config.php'; // Reset the template back to default if upgrading from a 1.x install: $ueConfig['templatedir'] = 'default'; $newConfig = json_encode($ueConfig); } // Convert CB 1.x nesttabs into new nested tab display mode if needed: if (isset($ueConfig['nesttabs'])) { // Update all the tabs that would have normally auto-nested and make them nested displays $query = 'UPDATE ' . $cbDatabase->NameQuote('#__comprofiler_tabs') . "\n SET " . $cbDatabase->NameQuote('displaytype') . " = " . $cbDatabase->Quote('nested') . "\n WHERE " . $cbDatabase->NameQuote('displaytype') . " = " . $cbDatabase->Quote('tab') . "\n AND " . $cbDatabase->NameQuote('fields') . " = 1" . "\n AND ( ( " . $cbDatabase->NameQuote('pluginclass') . " IS NULL )" . ' OR ( ' . $cbDatabase->NameQuote('sys') . ' = 2 ) )'; $cbDatabase->setQuery($query); $cbDatabase->query(); unset($ueConfig['nesttabs']); $newConfig = json_encode($ueConfig); } // Migrate global avatar params to field params: if (isset($ueConfig['allowAvatar']) || isset($ueConfig['defaultAvatar']) || isset($ueConfig['defaultPendingAvatar']) || isset($ueConfig['allowAvatarGallery'])) { $field = new FieldTable(); if ($field->load(array('name' => 'avatar'))) { $fieldParams = new Registry($field->params); if (isset($ueConfig['allowAvatar'])) { $fieldParams->set('image_allow_uploads', (int) $ueConfig['allowAvatar']); unset($ueConfig['allowAvatar']); } if (isset($ueConfig['defaultAvatar'])) { $fieldParams->set('defaultAvatar', $ueConfig['defaultAvatar']); unset($ueConfig['defaultAvatar']); } if (isset($ueConfig['defaultPendingAvatar'])) { $fieldParams->set('defaultPendingAvatar', $ueConfig['defaultPendingAvatar']); unset($ueConfig['defaultPendingAvatar']); } if (isset($ueConfig['allowAvatarGallery'])) { $fieldParams->set('image_allow_gallery', (int) $ueConfig['allowAvatarGallery']); unset($ueConfig['allowAvatarGallery']); } $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } $newConfig = json_encode($ueConfig); } // Migrate global email ajax checker to field specific param: if (isset($ueConfig['reg_email_checker'])) { $field = new FieldTable(); if ($field->load(array('name' => 'email'))) { $fieldParams = new Registry($field->params); $fieldParams->set('field_check_email', (string) $ueConfig['reg_email_checker']); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } unset($ueConfig['reg_email_checker']); $newConfig = json_encode($ueConfig); } // Migrate global image params to field params: if (isset($ueConfig['allowAvatarUpload'])) { $query = 'SELECT *' . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('name') . " != " . $cbDatabase->Quote('avatar') . "\n AND " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('image'); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); $fieldParams->set('image_allow_uploads', (int) $ueConfig['allowAvatarUpload']); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } unset($ueConfig['allowAvatarUpload']); $newConfig = json_encode($ueConfig); } // Convert CB 1.x allow_profileviewbyGID into new profile_viewaccesslevel if needed: if (isset($ueConfig['allow_profileviewbyGID']) && !isset($ueConfig['profile_viewaccesslevel'])) { $ueConfig['profile_viewaccesslevel'] = \CBLib\Application\Application::CmsPermissions()->convertOldGroupToViewAccessLevel($ueConfig['allow_profileviewbyGID'], 'CB Profiles access'); unset($ueConfig['allow_profileviewbyGID']); $newConfig = json_encode($ueConfig); } // Convert CB 1.x allow_profileviewbyGID into new profile_viewaccesslevel if needed: if (isset($ueConfig['imageApproverGid']) && !isset($ueConfig['moderator_viewaccesslevel'])) { $ueConfig['moderator_viewaccesslevel'] = \CBLib\Application\Application::CmsPermissions()->convertOldGroupToViewAccessLevel($ueConfig['imageApproverGid'], 'CB Moderators access'); unset($ueConfig['imageApproverGid']); $newConfig = json_encode($ueConfig); } // If old configuration for terms and conditions exists we need to pass it to the terms and conditions field: if (isset($ueConfig['reg_enable_toc']) && isset($ueConfig['reg_toc_url'])) { if ($ueConfig['reg_enable_toc'] == 1 && $ueConfig['reg_toc_url'] != '') { $field = new FieldTable(); if ($field->load(array('name' => 'acceptedterms'))) { $fieldParams = new Registry($field->params); if ($fieldParams->get('terms_url') == '') { $fieldParams->set('terms_url', $ueConfig['reg_toc_url']); $field->set('required', 1); $field->set('registration', 1); $field->set('edit', 1); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } } } unset($ueConfig['reg_enable_toc']); unset($ueConfig['reg_toc_url']); $newConfig = json_encode($ueConfig); } // If old configuration for userlists exists we need to pass it to the userlist it self: if (isset($ueConfig['num_per_page']) && isset($ueConfig['allow_profilelink'])) { if ($ueConfig['num_per_page'] != '' || $ueConfig['allow_profilelink'] != 1) { $query = 'SELECT *' . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_lists'); $cbDatabase->setQuery($query); $lists = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\ListTable', array($cbDatabase)); /** @var $lists ListTable[] */ foreach ($lists as $list) { $listParams = new Registry($list->params); $changed = false; if ($ueConfig['num_per_page'] != '' && $listParams->get('list_limit') == '') { $listParams->set('list_limit', $ueConfig['num_per_page']); $changed = true; } if ($ueConfig['allow_profilelink'] != 1 && $listParams->get('allow_profilelink') == '') { $listParams->set('allow_profilelink', $ueConfig['allow_profilelink']); $changed = true; } if ($changed) { $list->set('params', $listParams->asJson()); if (!$list->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Userlist [title] failed to migrate. Error: [error]', array('[name]' => $list->title, '[error]' => $list->getError())) . '</div>'; } } } } unset($ueConfig['num_per_page']); unset($ueConfig['allow_profilelink']); $newConfig = json_encode($ueConfig); } // Establish default for any missing config params: $configXml = new SimpleXMLElement(trim(file_get_contents($_CB_adminpath . 'xmlcb/views/view.com_comprofiler.editconfig.xml'))); if ($configXml) { $configXmlParams = $configXml->xpath('//param'); if ($configXmlParams) { $configXmlSet = false; foreach ($configXmlParams as $configXmlParam) { $k = (string) $configXmlParam->attributes('name'); if (!isset($ueConfig[$k])) { $v = (string) $configXmlParam->attributes('default'); if ($k) { $ueConfig[$k] = $v; $configXmlSet = true; } } } if ($configXmlSet) { $newConfig = json_encode($ueConfig); } } } // Update cb.core with the new cb config: if ($newConfig) { $query = "UPDATE " . $cbDatabase->NameQuote('#__comprofiler_plugin') . "\n SET " . $cbDatabase->NameQuote('params') . " = " . $cbDatabase->Quote($newConfig) . "\n WHERE " . $cbDatabase->NameQuote('id') . " = 1"; $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $_CB_framework->enqueueMessage(CBTxt::P('Failed to update configuration params in database. Error: [error]', array('[error]' => $cbDatabase->getErrorMsg())), 'error'); return false; } } // Remove the old config file if it exists as we migrated above already: if ($adminFS->file_exists($_CB_adminpath . 'ue_config.php')) { $adminFS->unlink($_CB_adminpath . 'ue_config.php'); } // Migrate old userlist columns to new usage: $tableFields = $cbDatabase->getTableFields('#__comprofiler_lists'); if (isset($tableFields['#__comprofiler_lists'])) { $userListFields = array_keys($tableFields['#__comprofiler_lists']); $userListOldFields = array('useraccessgroupid', 'sortfields', 'filterfields', 'col1title', 'col1enabled', 'col1fields', 'col1captions', 'col2title', 'col2enabled', 'col2fields', 'col2captions', 'col3title', 'col3enabled', 'col3fields', 'col3captions', 'col4title', 'col4enabled', 'col4fields', 'col4captions'); // At least 1 legacy column still exists so lets begin migration of userlists: if (array_intersect($userListOldFields, $userListFields)) { $query = 'SELECT *' . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_lists'); $cbDatabase->setQuery($query); $lists = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\ListTable', array($cbDatabase)); /** @var $lists ListTable[] */ foreach ($lists as $list) { $listParams = new Registry($list->params); $listSorting = array(); $listSortFields = $list->get('sortfields') ? explode(', ', str_replace('`', '', $list->get('sortfields'))) : array(); $paramsChanged = false; foreach ($listSortFields as $listSortField) { $sortParts = explode(' ', $listSortField); $sortField = isset($sortParts[0]) ? trim($sortParts[0]) : null; if ($sortField) { $sortDirection = isset($sortParts[1]) ? trim($sortParts[1]) : 'ASC'; $listSorting[] = array('column' => $sortField, 'direction' => $sortDirection); } } if ($listSorting) { $paramsChanged = true; $listParams->set('sort_mode', '0'); $listParams->set('basic_sort', $listSorting); } $listFilterFields = $list->get('filterfields'); if ($listFilterFields) { $filterType = substr($listFilterFields, 0, 1); $listFilterFields = rawurldecode(substr($listFilterFields, 2, -1)); if ($filterType == 'a') { $paramsChanged = true; $listParams->set('filter_mode', '1'); $listParams->set('filter_advanced', $listFilterFields); } else { $listFilters = array(); $basicFilters = explode(' AND ', $listFilterFields); foreach ($basicFilters as $basicFilter) { if (preg_match('/`(.+)`\\s*(.+)\\s*\'(.*)\'|`(.+)`\\s*(.+)/i', $basicFilter, $matches)) { $filterField = isset($filterParts[1]) ? $filterParts[1] : (isset($filterParts[4]) ? $filterParts[4] : null); $filterOperator = isset($filterParts[2]) ? $filterParts[2] : (isset($filterParts[5]) ? $filterParts[5] : null); $filterVal = isset($filterParts[3]) ? $filterParts[3] : ''; switch ($filterOperator) { case '!=': $filterOperator = '<>||ISNULL'; break; case 'IS NULL': case "= ''": $filterOperator = '='; $filterVal = ''; break; case 'IS NOT NULL': case "!= ''": $filterOperator = '!='; $filterVal = ''; break; } if ($filterField && $filterOperator) { $listFilters[] = array('column' => $filterField, 'operator' => $filterOperator, 'value' => $filterVal); } } } if ($listFilters) { $paramsChanged = true; $listParams->set('filter_mode', '0'); $listParams->set('filter_basic', $listFilters); } } } $listColumns = array(); for ($i = 1, $n = 4; $i <= $n; $i++) { if ($list->get('col' . $i . 'enabled')) { $columnTitle = $list->get('col' . $i . 'title', ''); $columnCaptions = (int) $list->get('col' . $i . 'captions', 0); $columnFields = $list->get('col' . $i . 'fields') ? explode('|*|', $list->get('col' . $i . 'fields')) : array(); $listFields = array(); foreach ($columnFields as $columnField) { $listFields[] = array('field' => (string) $columnField, 'display' => $columnCaptions ? '1' : '4'); } if ($listFields) { $listColumns[] = array('title' => $columnTitle, 'size' => '3', 'cssclass' => '', 'fields' => $listFields); } } } if ($listColumns) { $paramsChanged = true; $listParams->set('columns', $listColumns); } if ($paramsChanged || $list->get('usergroupids')) { $list->set('usergroupids', implode('|*|', explode(', ', $list->get('usergroupids')))); $list->set('params', $listParams->asJson()); if (!$list->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Userlist [title] failed to migrate. Error: [error]', array('[name]' => $list->title, '[error]' => $list->getError())) . '</div>'; } } } $userListDrop = array(); foreach ($userListOldFields as $userListOldField) { if (in_array($userListOldField, $userListFields)) { $userListDrop[] = $cbDatabase->NameQuote($userListOldField); } } if ($userListDrop) { $query = 'ALTER TABLE ' . $cbDatabase->NameQuote('#__comprofiler_lists') . "\n DROP " . implode(', DROP ', $userListDrop); $cbDatabase->setQuery($query); $cbDatabase->query(); } } } // Migrates password strength parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cbpasswordstrength'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('password'); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); $fieldParams->set('passTestSrength', (string) $fieldParams->get('pswstr_display', 1)); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates ajax points field parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cbajaxpointsfield'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " = " . $cbDatabase->Quote('ajaxpoints'); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); switch ((int) $fieldParams->get('ajax_layout', 1)) { case 1: $fieldParams->set('points_layout', '[minus] [value] [plus]'); break; case 2: $fieldParams->set('points_layout', '[plus] [value] [minus]'); break; case 3: $fieldParams->set('points_layout', '[value] [minus][plus]'); break; case 4: $fieldParams->set('points_layout', '[value] [plus][minus]'); break; case 5: $fieldParams->set('points_layout', '[minus][plus] [value]'); break; case 6: $fieldParams->set('points_layout', '[plus][minus] [value]'); break; } $fieldParams->set('points_inc_plus', (string) $fieldParams->get('ajax_increment_up', 1)); $fieldParams->set('points_inc_minus', (string) $fieldParams->get('ajax_increment_down', 1)); $fieldParams->set('points_access', '8'); $fieldParams->set('points_access_custom', (string) $fieldParams->get('ajax_access', 0)); $field->set('type', 'points'); $field->set('pluginid', 1); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates rating field parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'ratingfield'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " IN " . $cbDatabase->safeArrayOfStrings(array('myrating', 'yourrating')); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); if ($field->type == 'myrating') { $fieldParams->set('rating_access', '2'); } else { if ($fieldParams->get('AllowAnnonymous', 1)) { $fieldParams->set('rating_access', '3'); } else { $fieldParams->set('rating_access', '4'); $fieldParams->set('rating_access_exclude', '1'); } } $fieldParams->set('rating_number', (string) $fieldParams->get('NumStars', 5)); switch ((int) $fieldParams->get('RatingFraction', 1)) { case 1: $fieldParams->set('rating_step', '1'); break; case 2: $fieldParams->set('rating_step', '0.5'); break; case 3: $fieldParams->set('rating_step', '0.33'); break; case 4: $fieldParams->set('rating_step', '0.25'); break; } $field->set('type', 'rating'); $field->set('pluginid', 1); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates verify email field parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cbverifyemail'))) { $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('type') . " IN " . $cbDatabase->safeArrayOfStrings(array('emailaddress', 'primaryemailaddress')); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); $fieldParams->set('fieldVerifyInput', $fieldParams->get('verifyemail_display_reg', 1) || $fieldParams->get('verifyemail_display_edit', 0) ? '1' : '0'); $fieldParams->set('verifyEmailTitle', $fieldParams->get('verifyemail_title', '_UE_VERIFY_SOMETHING')); $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Migrates forum integration parameters: $plugin = new PluginTable(); if ($plugin->load(array('element' => 'cb.simpleboardtab'))) { $pluginParams = new Registry($plugin->params); $cbForums = new PluginTable(); if ($cbForums->load(array('element' => 'cbforums'))) { $cbForumsParams = new Registry($cbForums->params); if ((int) $pluginParams->get('forumType', 0) == 4) { $cbForumsParams->set('forum_model', '6'); } else { $cbForumsParams->set('forum_model', '1'); } switch ((int) $pluginParams->get('sidebarMode', 0)) { case 1: $cbForumsParams->set('k20_personaltext', $pluginParams->get('sidebarBeginner1')); $cbForumsParams->set('k20_gender', $pluginParams->get('sidebarBeginner4')); $cbForumsParams->set('k20_birthdate', $pluginParams->get('sidebarBeginner2')); $cbForumsParams->set('k20_location', $pluginParams->get('sidebarBeginner3')); $cbForumsParams->set('k20_icq', $pluginParams->get('sidebarBeginner5')); $cbForumsParams->set('k20_aim', $pluginParams->get('sidebarBeginner6')); $cbForumsParams->set('k20_yim', $pluginParams->get('sidebarBeginner7')); $cbForumsParams->set('k20_msn', $pluginParams->get('sidebarBeginner8')); $cbForumsParams->set('k20_skype', $pluginParams->get('sidebarBeginner9')); $cbForumsParams->set('k20_twitter', $pluginParams->get('sidebarBeginner12')); $cbForumsParams->set('k20_facebook', $pluginParams->get('sidebarBeginner13')); $cbForumsParams->set('k20_gtalk', $pluginParams->get('sidebarBeginner10')); $cbForumsParams->set('k20_myspace', $pluginParams->get('sidebarBeginner14')); $cbForumsParams->set('k20_linkedin', $pluginParams->get('sidebarBeginner15')); $cbForumsParams->set('k20_delicious', $pluginParams->get('sidebarBeginner16')); $cbForumsParams->set('k20_digg', $pluginParams->get('sidebarBeginner18')); $cbForumsParams->set('k20_blogspot', $pluginParams->get('sidebarBeginner19')); $cbForumsParams->set('k20_flickr', $pluginParams->get('sidebarBeginner20')); $cbForumsParams->set('k20_bebo', $pluginParams->get('sidebarBeginner21')); $cbForumsParams->set('k20_website', $pluginParams->get('sidebarBeginner11')); break; case 2: $cbForumsParams->set('k20_sidebar_reg', $pluginParams->get('sidebarAdvancedExists')); $cbForumsParams->set('k20_sidebar_anon', $pluginParams->get('sidebarAdvancedPublic')); $cbForumsParams->set('k20_sidebar_del', $pluginParams->get('sidebarAdvancedDeleted')); break; } $cbForums->set('params', $cbForumsParams->asJson()); if (!$cbForums->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Plugin [element] failed to migrate. Error: [error]', array('[element]' => $plugin->element, '[error]' => $cbForums->getError())) . '</div>'; } } // Migrate the forum fields to ensure their display mode is set: $query = "SELECT *" . "\n FROM " . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n WHERE " . $cbDatabase->NameQuote('name') . " IN " . $cbDatabase->safeArrayOfStrings(array('forumrank', 'forumposts', 'forumkarma')); $cbDatabase->setQuery($query); $fields = $cbDatabase->loadObjectList(null, '\\CB\\Database\\Table\\FieldTable', array($cbDatabase)); /** @var $fields FieldTable[] */ foreach ($fields as $field) { $fieldParams = new Registry($field->params); switch ($field->name) { case 'forumposts': $fieldParams->set('forumStatus', 'posts'); break; case 'forumkarma': $fieldParams->set('forumStatus', 'karma'); break; case 'forumrank': $fieldParams->set('forumStatus', 'rank'); break; } $field->set('params', $fieldParams->asJson()); if (!$field->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Field [name] failed to migrate. Error: [error]', array('[name]' => $field->name, '[error]' => $field->getError())) . '</div>'; } } if (!cbInstaller_uninstall_plugin($plugin, $return)) { return false; } } // Removes legacy about cb menu items from CB Menu tab params $tab = new TabTable(); if ($tab->load(17)) { $tabParams = new Registry($tab->params); if ($tabParams->get('firstSubMenuName') == '_UE_MENU_ABOUT_CB') { $tabParams->set('firstSubMenuName', ''); $tabParams->set('firstSubMenuHref', ''); if ($tabParams->get('firstMenuName') == '_UE_MENU_CB' && !$tabParams->get('secondSubMenuName')) { $tabParams->set('firstMenuName', ''); } $tab->set('params', $tabParams->asJson()); if (!$tab->store()) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Tab [title] failed to migrate. Error: [error]', array('[title]' => $tab->title, '[error]' => $tab->getError())) . '</div>'; } } } // We need to fix the name fields publish state: switch ($ueConfig['name_style']) { case 2: $nameArray = array('name' => 0, 'firstname' => 1, 'middlename' => 0, 'lastname' => 1); break; case 3: $nameArray = array('name' => 0, 'firstname' => 1, 'middlename' => 1, 'lastname' => 1); break; case 1: default: $nameArray = array('name' => 1, 'firstname' => 0, 'middlename' => 0, 'lastname' => 0); break; } foreach ($nameArray as $name => $published) { $query = 'UPDATE ' . $cbDatabase->NameQuote('#__comprofiler_fields') . "\n SET " . $cbDatabase->NameQuote('published') . " = " . (int) $published . "\n WHERE " . $cbDatabase->NameQuote('name') . " = " . $cbDatabase->Quote($name); $cbDatabase->setQuery($query); $cbDatabase->query(); } return true; }
/** * @param null|string|int|TabTable[] $tabs * @param string $reason * @param int $userId * @param bool $jquery * @param string $formatting * @param bool $tabbed * @return array */ private function getTabConditional( $tabs, $reason, $userId, $jquery = false, $formatting = 'table', $tabbed = true ) { global $_CB_database, $_CB_framework; $disabled = array(); static $userCache = array(); if ( ! isset( $userCache[$userId] ) ) { $cbUser = CBuser::getInstance( (int) $userId, false ); $cmsUser = Application::User( (int) $userId ); $userCache[$userId] = array( $cbUser, $cbUser->getUserData(), $cmsUser->getAuthorisedViewLevels(), $cmsUser->getAuthorisedGroups() ); } /** @var CBuser $cbUser */ $cbUser = $userCache[$userId][0]; /** @var UserTable $user */ $user = $userCache[$userId][1]; /** @var array $userAccessLevels */ $userAccessLevels = $userCache[$userId][2]; /** @var array $userUsergroups */ $userUsergroups = $userCache[$userId][3]; static $tabCache = array(); if ( ! $tabs ) { /** @var TabTable[] $tabsCache */ static $tabsCache = array(); if ( ! isset( $tabsCache[$user->id] ) ) { $cbTabs = $cbUser->_getCbTabs(); $tabsCache[$user->id] = $cbTabs->_getTabsDb( $user, 'adminfulllist' ); } $tabs = $tabsCache[$user->id]; } elseif ( ! is_array( $tabs ) ) { if ( is_string( $tabs ) || is_integer( $tabs ) ) { $tabId = (int) $tabs; if ( $tabId ) { if ( ! isset( $tabCache[$tabId] ) ) { $tab = new TabTable(); $tab->load( $tabId ); $tabCache[$tabId] = $tab; } $tabs = $tabCache[$tabId]; } } $tabs = array( $tabs ); } elseif ( is_array( $tabs ) ) { $tabArray = array(); foreach ( $tabs as $tabId ) { if ( is_string( $tabId ) || is_integer( $tabId ) ) { $tabId = (int) $tabId; if ( $tabId ) { if ( ! isset( $tabCache[$tabId] ) ) { $tab = new TabTable(); $tab->load( $tabId ); $tabCache[$tabId] = $tab; } $tabArray[] = $tabCache[$tabId]; } } elseif ( $tabId instanceof TabTable ) { $tabArray[] = $tabId; } } $tabs = $tabArray; } /** @var Registry[] $tabParams */ static $tabParams = array(); /** @var FieldTable[] $fields */ static $fields = array(); /** @var FieldTable[] $tabFields */ static $tabFields = array(); /** @var array[] $conditioned */ static $conditioned = array(); $uId = (int) $user->get( 'id' ); if ( $tabs ) foreach ( $tabs as $tab ) { if ( $tab instanceof TabTable ) { $tId = (int) $tab->get( 'tabid' ); if ( ! isset( $conditioned[$tId][$uId][$reason][$jquery] ) ) { $tabConditions = array(); $conditioned[$tId][$uId][$reason][$jquery] = $tabConditions; if ( ! isset( $tabParams[$tId] ) ) { if ( ! ( $tab->params instanceof ParamsInterface ) ) { $tab->params = new Registry( $tab->params ); } $tabParams[$tId] = $tab->params; } $params = $tabParams[$tId]; for ( $i = 1; $i <= 5; $i++ ) { $conditional = ( $i > 1 ? $i : null ); $display = (int) $params->get( 'cbconditional_display' . $conditional, 0 ); if ( $reason == 'profile' ) { if ( ! $params->get( 'cbconditional_target_view' . $conditional, 1 ) ) { $display = 0; } } elseif ( $reason == 'edit' ) { if ( ! $params->get( 'cbconditional_target_edit' . $conditional, 0 ) ) { $display = 0; } } elseif ( $reason == 'register' ) { if ( ! $params->get( 'cbconditional_target_reg' . $conditional, 0 ) ) { $display = 0; } } if ( $display ) { $fieldName = $params->get( 'cbconditional_field' . $conditional, null ); if ( $fieldName ) { $operator = (int) $params->get( 'cbconditional_operator' . $conditional, 0 ); $value = $cbUser->replaceUserVars( $params->get( 'cbconditional_value' . $conditional, null ), false, true, $this->getExtras(), ( (int) $params->get( 'cbconditional_value_translate' . $conditional, 0 ) ? true : false ) ); if ( in_array( $operator, array( '6', '7' ) ) ) { $value = null; } $mode = (int) $params->get( 'cbconditional_mode' . $conditional, 0 ); switch ( $fieldName ) { case 'customvalue': $fieldValue = $cbUser->replaceUserVars( $params->get( 'cbconditional_customvalue' . $conditional, null ), false, true, $this->getExtras(), ( (int) $params->get( 'cbconditional_customvalue_translate' . $conditional, 0 ) ? true : false ) ); break; case 'customviewaccesslevels': $accessLevels = cbToArrayOfInt( explode( '|*|', $params->get( 'cbconditional_customviewaccesslevels' . $conditional, null ) ) ); $fieldValue = 0; foreach ( $accessLevels as $accessLevel ) { if ( in_array( $accessLevel, $userAccessLevels ) ) { $fieldValue = 1; break; } } $operator = 0; $value = 1; break; case 'customusergroups': $userGroups = cbToArrayOfInt( explode( '|*|', $params->get( 'cbconditional_customusergroups' . $conditional, null ) ) ); $fieldValue = 0; foreach ( $userGroups as $userGroup ) { if ( in_array( $userGroup, $userUsergroups ) ) { $fieldValue = 1; break; } } $operator = 0; $value = 1; break; default: if ( ! isset( $fields[$fieldName] ) ) { $field = new FieldTable(); $field->load( array( 'name' => $fieldName ) ); $fields[$fieldName] = $field; } $fieldValue = $this->getFieldValue( $user, $cbUser, $fields[$fieldName], $reason ); break; } if ( $jquery ) { $_CB_framework->addJQueryPlugin( 'cbcondition', '/components/com_comprofiler/plugin/user/plug_cbconditional/js/cbcondition.js' ); $js = "var tabCondition = ['#cbtp_$tId'];"; if ( $tabbed ) { $js .= "tabCondition.push( '#cbtabpane$tId' );"; } else { if ( in_array( $formatting, array( 'tables', 'divs' ) ) ) { $js .= "tabCondition.push( '#cbtf_$tId' );"; } else { if ( ! isset( $tabFields[$tId] ) ) { $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_fields' ) . "\n WHERE " . $_CB_database->NameQuote( 'tabid' ) . " = " . (int) $tId; $_CB_database->setQuery( $query ); $tabFields[$tId] = $_CB_database->loadObjectList( null, '\CB\Database\Table\FieldTable', array( $_CB_database ) ); } foreach ( $tabFields[$tId] as $tabField ) { /** @var FieldTable $tabField */ $fId = (int) $tabField->get( 'fieldid' ); $js .= "tabCondition.push( '#cbfr_$fId,#cbfr_' . $fId . '__verify,#cbfrd_$fId,#cbfrd_' . $fId . '__verify' );"; } } } switch ( $fieldName ) { case 'customvalue': case 'customviewaccesslevels': case 'customusergroups': $js .= "$.cbcondition({" . "conditions: [{" . "operator: " . (int) $operator . "," . "input: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $fieldValue ) ? implode( '|*|', $fieldValue ) : $fieldValue ) ) ) . "'," . "value: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $value ) ? implode( '|*|', $value ) : $value ) ) ) . "'," . ( $mode ? "show: tabCondition," : "hide: tabCondition," ) . "reset: " . (int) $this->params->get( 'cond_reset', 0 ) . "" . "}]" . "});"; break; default: $fieldId = $fields[$fieldName]->get( 'fieldid' ); if ( $fieldId ) { $js .= "$( '#cbfr_" . (int) $fieldId . ",#cbfrd_" . (int) $fieldId . "' ).cbcondition({" . "conditions: [{" . "operator: " . (int) $operator . "," . "input: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $fieldValue ) ? implode( '|*|', $fieldValue ) : $fieldValue ) ) ) . "'," . "value: '" . addslashes( str_replace( array( "\n", "\r" ), array( "\\n", "\\r" ), ( is_array( $value ) ? implode( '|*|', $value ) : $value ) ) ) . "'," . ( $mode ? "show: tabCondition," : "hide: tabCondition," ) . "reset: " . (int) $this->params->get( 'cond_reset', 0 ) . "" . "}]" . "});"; } break; } $_CB_framework->outputCbJQuery( $js, 'cbcondition' ); } $tabConditions[] = array( 'match' => $this->getMatch( $fieldValue, $operator, $value ), 'mode' => $mode, 'tab' => $tId ); } } } $conditioned[$tId][$uId][$reason][$jquery] = $tabConditions; } $conditions = $conditioned[$tId][$uId][$reason][$jquery]; foreach ( $conditions as $cond ) { if ( $cond['match'] ) { if ( ( ! $cond['mode'] ) && ( ! in_array( $cond['tab'], $disabled ) ) ) { array_push( $disabled, $cond['tab'] ); } } else { if ( $cond['mode'] && ( ! in_array( $cond['tab'], $disabled ) ) ) { array_push( $disabled, $cond['tab'] ); } } } } } return $disabled; }
/** * @param TabTable $tab Current tab * @param UserTable $user Current user * @param int $ui 1 front, 2 admin UI * @param array $postdata Raw unfiltred POST data * @return string HTML */ public function getCBpluginComponent( $tab, $user, $ui, $postdata ) { global $_CB_framework; $format = $this->input( 'format', null, GetterInterface::STRING ); $raw = ( $format == 'raw' ); if ( ! $raw ) { outputCbJs(); outputCbTemplate(); } $action = null; $function = null; $id = null; $viewer = CBuser::getMyUserDataInstance(); $user = $viewer; $stream = null; $inline = false; $data = true; if ( isset( $postdata['stream'] ) && ( $postdata['stream'] instanceof StreamInterface ) ) { $stream = $postdata['stream']; if ( $stream instanceof ActivityInterface ) { $action = 'activity'; $function = 'show'; } elseif ( $stream instanceof CommentsInterface ) { $action = 'comments'; $function = 'show'; } elseif ( $stream instanceof TagsInterface ) { $action = 'tags'; $function = 'show'; } if ( isset( $postdata['inline'] ) ) { $inline = $postdata['inline']; } if ( isset( $postdata['data'] ) ) { $data = $postdata['data']; } $user = $stream->user(); } else { $action = $this->input( 'action', null, GetterInterface::STRING ); $function = $this->input( 'func', null, GetterInterface::STRING ); if ( $action == 'recentactivity' ) { $action = 'activity'; $function = 'recent'; } elseif ( $action == 'myactivity' ) { $action = 'activity'; $function = 'my'; } elseif ( $action == 'hiddenactivity' ) { $action = 'hidden'; $function = 'activity'; } elseif ( $action == 'hiddencomments' ) { $action = 'hidden'; $function = 'comments'; } if ( ( $action == 'activity' ) || ( $function == 'activity' ) ) { $stream = new Activity(); } elseif ( ( $action == 'comments' ) || ( $function == 'comments' ) ) { $stream = new Comments(); } elseif ( ( $action == 'tags' ) || ( $function == 'tags' ) ) { $stream = new Tags(); } if ( $stream && $raw ) { $token = $this->input( 'token', null, GetterInterface::STRING ); $post = new Registry( base64_decode( $this->input( 'stream', null, GetterInterface::BASE64 ) ) ); $source = $post->get( 'source', null, GetterInterface::STRING ); $userId = $post->get( 'user', null, GetterInterface::INT ); $direction = $post->get( 'direction', null, GetterInterface::INT ); if ( $source !== null ) { $stream->source( $source ); } if ( $userId !== null ) { $user = CBuser::getUserDataInstance( (int) $userId ); $stream->user( $user ); } if ( ! ( $stream instanceof TagsInterface ) ) { if ( $direction !== null ) { $stream->direction( $direction ); } } $stream->load( $post ); if ( ( $stream->token() != $token ) || ( ! $token ) ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } $id = $stream->get( 'id', null, GetterInterface::INT ); } } if ( $stream && ( ! ( ( $stream instanceof CommentsInterface ) || ( $stream instanceof TagsInterface ) ) ) ) { $hashtag = $this->input( 'hashtag', null, GetterInterface::STRING ); if ( $hashtag !== null ) { $stream->set( 'filter', '#' . $hashtag ); } } if ( ! $raw ) { ob_start(); } switch ( $action ) { case 'comments': if ( ! $stream ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } } switch ( $function ) { case 'new': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->saveComment( null, $stream, $user, $viewer ); break; case 'save': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->saveComment( $id, $stream, $user, $viewer ); break; case 'delete': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->deleteComment( $id, $stream, $user, $viewer ); break; case 'hide': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->hideComment( $id, $stream, $user, $viewer ); break; case 'unhide': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->unhideComment( $id, $stream, $user, $viewer ); break; case 'load': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->showComments( $id, $stream, 3, true, $user, $viewer ); break; case 'show': default: if ( isset( $postdata['stream'] ) && ( $postdata['stream'] instanceof CommentsInterface ) ) { $this->showComments( $id, $stream, ( $inline ? 2 : 0 ), $data, $user, $viewer ); } else { $this->showComments( $id, $stream, ( $inline ? 2 : ( $raw ? 1 : 0 ) ), true, $user, $viewer ); } break; } break; case 'activity': if ( ! $stream ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } } switch ( $function ) { case 'new': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->saveActivity( null, $stream, $user, $viewer ); break; case 'save': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->saveActivity( $id, $stream, $user, $viewer ); break; case 'delete': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->deleteActivity( $id, $stream, $user, $viewer ); break; case 'hide': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->hideActivity( $id, $stream, $user, $viewer ); break; case 'unhide': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->unhideActivity( $id, $stream, $user, $viewer ); break; case 'load': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->showActivity( $id, $stream, 3, true, $user, $viewer ); break; case 'recent': $stream->source( 'recent' ); $menu = JFactory::getApplication()->getMenu()->getActive(); if ( $menu && isset( $menu->id ) ) { CBActivity::loadStreamDefaults( $stream, $menu->params, 'activity_' ); } $this->showActivity( $id, $stream, ( $raw ? 1 : 0 ), true, $user, $viewer ); $_CB_framework->setMenuMeta(); break; case 'my': $tab = new TabTable(); $tab->load( array( 'pluginclass' => 'cbactivityTab' ) ); if ( ! ( $tab->get( 'enabled' ) && CBActivity::canAccess( (int) $tab->get( 'viewaccesslevel' ), (int) $viewer->get( 'id' ) ) ) ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( $_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, 'cbactivityTab' ), CBTxt::T( 'Not authorized.' ), 'error' ); } } if ( ! ( $tab->params instanceof ParamsInterface ) ) { $tab->params = new Registry( $tab->params ); } $stream->source( 'profile' ); CBActivity::loadStreamDefaults( $activity, $tab->params, 'tab_activity_' ); $this->showActivity( $id, $stream, ( $raw ? 1 : 0 ), true, $user, $viewer ); $_CB_framework->setMenuMeta(); break; case 'show': default: if ( isset( $postdata['stream'] ) && ( $postdata['stream'] instanceof ActivityInterface ) ) { $this->showActivity( $id, $stream, ( $inline ? 2 : 0 ), $data, $user, $viewer ); } else { $this->showActivity( $id, $stream, ( $inline ? 2 : ( $raw ? 1 : 0 ) ), true, $user, $viewer ); } break; } break; case 'hidden': if ( ! $stream ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } } switch ( $function ) { case 'users': break; case 'types': break; case 'comments': $stream->source( 'hidden' ); $stream->set( 'create_access', -1 ); $stream->set( 'replies', 0 ); $this->showComments( $id, $stream, ( $raw ? 1 : 0 ), true, $user, $viewer ); break; case 'activity': $stream->source( 'hidden' ); $stream->set( 'create_access', -1 ); $stream->set( 'comments', 0 ); $this->showActivity( $id, $stream, ( $raw ? 1 : 0 ), true, $user, $viewer ); break; } $_CB_framework->setMenuMeta(); break; case 'tags': if ( ! $stream ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } } switch ( $function ) { case 'show': default: if ( isset( $postdata['stream'] ) && ( $postdata['stream'] instanceof TagsInterface ) ) { $this->showTags( $id, $stream, ( $inline ? 2 : 0 ), $data, $user, $viewer ); } else { $this->showTags( $id, $stream, ( $inline ? 2 : ( $raw ? 1 : 0 ) ), true, $user, $viewer ); } break; } break; case 'cleanup': if ( ( ! $raw ) || ( $this->input( 'token', null, GetterInterface::STRING ) != md5( $_CB_framework->getCfg( 'secret' ) ) ) ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } $this->cleanUp(); break; } if ( ! $raw ) { $html = ob_get_contents(); ob_end_clean(); if ( ! $inline ) { $class = $this->params->get( 'general_class', null ); $html = '<div id="cbActivity" class="cbActivity' . ( $class ? ' ' . htmlspecialchars( $class ) : null ) . '">' . '<div id="cbActivityInner" class="cbActivityInner">' . $html . '</div>' . '</div>'; } echo $html; } }
/** * @param TabTable|int $tab * @return bool */ static public function checkTabEditAccess( $tab ) { if ( self::checkUserModerator() ) { return true; } static $tabs = array(); static $cache = array(); $return = true; if ( is_integer( $tab ) ) { if ( ! isset( $tabs[$tab] ) ) { $loadedTab = new TabTable(); $loadedTab->load( $tab ); $tabs[$tab] = $loadedTab; } $tab = $tabs[$tab]; } if ( $tab instanceof TabTable ) { $myId = Application::MyUser()->getUserId(); $tabId = (int) $tab->get( 'tabid' ); if ( ! isset( $cache[$tabId][$myId] ) ) { $authorized = true; if ( ! ( $tab->params instanceof ParamsInterface ) ) { $tab->params = new Registry( $tab->params ); } $display = $tab->params->get( 'cbprivacy_edit', '0' ); if ( ( $display == 1 ) || ( ( $display == 2 ) && ( ! self::checkUserModerator() ) ) || ( ( $display == 3 ) && ( ! Application::MyUser()->canViewAccessLevel( $tab->params->get( 'cbprivacy_edit_access', '1' ) ) ) ) ) { $authorized = false; } $cache[$tabId][$myId] = $authorized; } $return = $cache[$tabId][$myId]; } return $return; }