public function ajaxRemoveFeatured($memberId) { $filter = JFilterInput::getInstance(); $memberId = $filter->clean($memberId, 'int'); $my = CFactory::getUser(); if ($my->id == 0) { return $this->ajaxBlockUnregister(); } if (COwnerHelper::isCommunityAdmin()) { $model = CFactory::getModel('Featured'); //CFactory::load( 'libraries' , 'featured' ); $featured = new CFeatured(FEATURED_USERS); $my = CFactory::getUser(); if ($featured->delete($memberId)) { $html = JText::_('COM_COMMUNITY_USER_REMOVED_FROM_FEATURED'); } else { $html = JText::_('COM_COMMUNITY_REMOVING_USER_FROM_FEATURED_ERROR'); } } else { $html = JText::_('COM_COMMUNITY_NOT_ALLOWED_TO_ACCESS_SECTION'); } $actions = '<input type="button" class="btn" onclick="window.location.reload();" value="' . JText::_('COM_COMMUNITY_BUTTON_CLOSE_BUTTON') . '"/>'; $this->cacheClean(array(COMMUNITY_CACHE_TAG_FEATURED)); $json = array(); $json['title'] = ' '; $json['html'] = $html; die(json_encode($json)); }
public function ajaxRemoveFeatured($memberId) { $objResponse = new JAXResponse(); CFactory::load('helpers', 'owner'); $my = CFactory::getUser(); if ($my->id == 0) { return $this->ajaxBlockUnregister(); } if (COwnerHelper::isCommunityAdmin()) { $model = CFactory::getModel('Featured'); CFactory::load('libraries', 'featured'); $featured = new CFeatured(FEATURED_USERS); $my = CFactory::getUser(); if ($featured->delete($memberId)) { $objResponse->addAssign('cWindowContent', 'innerHTML', JText::_('CC USER REMOVED FROM FEATURED')); } else { $objResponse->addAssign('cWindowContent', 'innerHTML', JText::_('CC ERROR REMOVING USER FROM FEATURED')); } } else { $objResponse->addAssign('cWindowContent', 'innerHTML', JText::_('CC NOT ALLOWED TO ACCESS SECTION')); } $buttons = '<input type="button" class="button" onclick="window.location.reload();" value="' . JText::_('CC BUTTON CLOSE') . '"/>'; $objResponse->addScriptCall('cWindowActions', $buttons); return $objResponse->sendResponse(); }
public function ajaxRemoveFeatured($memberId) { $filter = JFilterInput::getInstance(); $memberId = $filter->clean($memberId, 'int'); $objResponse = new JAXResponse(); CFactory::load('helpers', 'owner'); $my = CFactory::getUser(); if ($my->id == 0) { return $this->ajaxBlockUnregister(); } if (COwnerHelper::isCommunityAdmin()) { $model = CFactory::getModel('Featured'); CFactory::load('libraries', 'featured'); $featured = new CFeatured(FEATURED_USERS); $my = CFactory::getUser(); if ($featured->delete($memberId)) { $html = JText::_('COM_COMMUNITY_USER_REMOVED_FROM_FEATURED'); } else { $html = JText::_('COM_COMMUNITY_REMOVING_USER_FROM_FEATURED_ERROR'); } } else { $html = JText::_('COM_COMMUNITY_NOT_ALLOWED_TO_ACCESS_SECTION'); } $actions = '<input type="button" class="button" onclick="window.location.reload();" value="' . JText::_('COM_COMMUNITY_BUTTON_CLOSE_BUTTON') . '"/>'; $objResponse->addScriptCall('cWindowAddContent', $html, $actions); $this->cacheClean(array(COMMUNITY_CACHE_TAG_FEATURED)); return $objResponse->sendResponse(); }
public function deleteGroup() { require_once JPATH_ROOT . '/components/com_community/libraries/featured.php'; require_once JPATH_ROOT . '/components/com_community/defines.community.php'; $featured = new CFeatured(FEATURED_GROUPS); $groupWithError = array(); $group = JTable::getInstance('Group', 'CTable'); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $id = $jinput->post->get('cid', '', 'NONE'); //JRequest::getVar( 'cid' , '' , 'post' ); if (empty($id)) { JError::raiseError('500', JText::_('COM_COMMUNITY_INVALID_ID')); } foreach ($id as $data) { require_once JPATH_ROOT . '/components/com_community/models/groups.php'; //delete group bulletins CommunityModelGroups::deleteGroupBulletins($data); //delete group members CommunityModelGroups::deleteGroupMembers($data); //delete group wall CommunityModelGroups::deleteGroupWall($data); //delete group discussions CommunityModelGroups::deleteGroupDiscussions($data); //delete group media files CommunityModelGroups::deleteGroupMedia($data); //load group data before delete $group->load($data); $groupData = $group; //delete group avatar. jimport('joomla.filesystem.file'); if (!empty($groupData->avatar)) { //images/avatar/groups/d203ccc8be817ad5b6a8335c.png $path = explode('/', $groupData->avatar); $file = JPATH_ROOT . '/' . $path[0] . '/' . $path[1] . '/' . $path[2] . '/' . $path[3]; if (file_exists($file)) { JFile::delete($file); } } if (!empty($groupData->thumb)) { //images/avatar/groups/thumb_d203ccc8be817ad5b6a8335c.png $path = explode('/', $groupData->thumb); $file = JPATH_ROOT . '/' . $path[0] . '/' . $path[1] . '/' . $path[2] . '/' . $path[3]; if (file_exists($file)) { JFile::delete($file); } } if (!$group->delete($data)) { array_push($groupWithError, $data . ':' . $groupData->name); } $featured->delete($data); } $message = ''; if (empty($error)) { $message = JText::_('COM_COMMUNITY_GROUP_DELETED'); } else { $error = implode(',', $groupWithError); $message = JText::sprintf('COM_COMMUNITY_GROUPS_DELETE_GROUP_ERROR', $error); } $mainframe = JFactory::getApplication(); $mainframe->redirect('index.php?option=com_community&view=groups', $message, 'message'); }
public function ajaxRemoveFeatured($albumId) { $filter = JFilterInput::getInstance(); $albumId = $filter->clean($albumId, 'int'); $json = array(); $my = CFactory::getUser(); if ($my->id == 0) { return $this->ajaxBlockUnregister(); } if (COwnerHelper::isCommunityAdmin()) { $model = CFactory::getModel('Featured'); $featured = new CFeatured(FEATURED_ALBUMS); if ($featured->delete($albumId)) { $json['success'] = true; $json['html'] = JText::_('COM_COMMUNITY_PHOTOS_ALBUM_REMOVED_FROM_FEATURED'); } else { $json['error'] = JText::_('COM_COMMUNITY_REMOVING_ALBUM_FROM_FEATURED_ERROR'); } } else { $json['error'] = JText::_('COM_COMMUNITY_NOT_ALLOWED_TO_ACCESS_SECTION'); } die(json_encode($json)); }
/** * Delete an album * Set all photo within the album to have albumid = 0 * Do not yet delete the photos, this could be very slow on an album that * has huge amount of photos */ public function delete($pk = null) { //lets get all the photo info under the album $photoModel = CFactory::getModel('photos'); $photos = $photoModel->getAllPhotos($this->id, $this->type); $db = JFactory::getDBO(); $strSQL = 'UPDATE ' . $db->quoteName('#__community_photos') . ' SET ' . $db->quoteName('albumid') . '=' . $db->Quote(0) . ', ' . $db->quoteName('status') . ' = ' . $db->quote('temp') . ' WHERE ' . $db->quoteName('albumid') . '=' . $db->Quote($this->id); $db->setQuery($strSQL); $result = $db->query(); // The whole local folder should be deleted, regardless of the storage type // BUT some old version of JomSocial might store other photo in the same // folder, we check in db first $strSQL = 'SELECT count(*) FROM ' . $db->quoteName('#__community_photos') . ' WHERE ' . $db->quoteName('image') . ' LIKE ' . $db->Quote('%' . dirname($this->path) . '%'); $db->setQuery($strSQL); $result = $db->loadResult(); if ($result == 0) { if (JFolder::exists(JPATH_ROOT . '/' . rtrim($this->path, '/') . '/' . $this->id)) { JFolder::delete(JPATH_ROOT . '/' . rtrim($this->path, '/') . '/' . $this->id); } } // We need to delete all activity stream related to this album CActivityStream::remove('photos', $this->id); //we need to delete all activity related to the photos inside the album as well if (isset($photos) && count($photos) > 0) { foreach ($photos as $photo) { CActivityStream::remove('photos', $photo->id); } } /* Delete album directory */ $config = CFactory::getConfig(); $dirPath = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/photos/' . $this->creator . '/' . $this->id; if (JFolder::exists($dirPath)) { JFolder::delete($dirPath); } $appsLib = CAppPlugins::getInstance(); $appsLib->loadApplications(); $appsLib->triggerEvent('onAfterAlbumDelete', array($this)); // @rule: remove from featured item if item is featured $featured = new CFeatured(FEATURED_ALBUMS); $featured->delete($this->id); // if this is an avatar, we have to remove the avatar from the respective user if ($this->type == 'profile.avatar') { $user = CFactory::getUser($this->creator); $userModel = CFactory::getModel('User'); $userModel->removeProfilePicture($user->id, 'avatar'); $userModel->removeProfilePicture($user->id, 'thumb'); $activityModel = CFactory::getModel('activities'); $activityModel->removeAvatarActivity('profile.avatar.upload', $user->id); } elseif ($this->type == 'event.avatar') { $eventTable = JTable::getInstance('Event', 'CTable'); $eventTable->load($this->eventid); $eventTable->removeAvatar(); $activityModel = CFactory::getModel('activities'); $activityModel->removeAvatarActivity('events.avatar.upload', $this->eventid); } elseif ($this->type == 'group.avatar') { $eventTable = JTable::getInstance('Group', 'CTable'); $eventTable->load($this->groupid); $eventTable->removeAvatar(); $activityModel = CFactory::getModel('activities'); $activityModel->removeAvatarActivity('groups.avatar.upload', $this->groupid); } //add user points CUserPoints::assignPoint('album.remove'); // Remove from activity stream //CActivityStream::remove('photos', $this->id); // Remove from activity stream CActivityStream::remove('albums', $this->id); // Remove likes activity $likeModel = CFactory::getModel('like'); $likeModel->removeLikes('album', $this->id); // Remove comment $wallModel = CFactory::getModel('wall'); $wallModel->deletePostByType('albums', $this->id); return parent::delete(); }
/** * Delete group's media * * param string id The id of the group. * **/ public static function deleteGroupMedia($gid) { $db = JFactory::getDBO(); $photosModel = CFactory::getModel('photos'); $videoModel = CFactory::getModel('videos'); $fileModel = CFactory::getModel('files'); // group's photos removal. $albums = $photosModel->getGroupAlbums($gid, false, false, 0); foreach ($albums as $item) { $photos = $photosModel->getAllPhotos($item->id, PHOTOS_GROUP_TYPE); foreach ($photos as $row) { $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($row->id); $photo->delete(); } //now we delete group photo album folder $album = JTable::getInstance('Album', 'CTable'); $album->load($item->id); $album->delete(); } //group's videos $featuredVideo = new CFeatured(FEATURED_VIDEOS); $videos = $videoModel->getGroupVideos($gid); foreach ($videos as $vitem) { if (!$vitem) { continue; } $video = JTable::getInstance('Video', 'CTable'); $videaId = (int) $vitem->id; $video->load($videaId); if ($video->delete()) { // Delete all videos related data $videoModel->deleteVideoWalls($videaId); $videoModel->deleteVideoActivities($videaId); //remove featured video $featuredVideo->delete($videaId); //remove the physical file $storage = CStorage::getStorage($video->storage); if ($storage->exists($video->thumb)) { $storage->delete($video->thumb); } if ($storage->exists($video->path)) { $storage->delete($video->path); } } } $fileModel->alldelete($gid, 'group'); return true; }
/** * Controller method to remove an album **/ public function removealbum() { if ($this->blockUnregister()) { return; } // Check for request forgeries JRequest::checkToken() or jexit(JText::_('CC INVALID TOKEN')); // Get the album id. $my = CFactory::getUser(); $id = JRequest::getInt('albumid', ''); $task = JRequest::getCmd('currentTask', ''); $album =& JTable::getInstance('Album', 'CTable'); $album->load($id); if ($album->permanent == 1) { return; } /** HTGMOD **/ $handler = $this->_getHandler($album); // Load libraries CFactory::load('models', 'photos'); CFactory::load('libraries', 'activities'); $album =& JTable::getInstance('Album', 'CTable'); $album->load($id); CFactory::load('helpers', 'owner'); if (!$handler->hasPermission($album->id)) { $this->blockUserAccess(); return; } $model = CFactory::getModel('photos'); CFactory::load('libraries', 'apps'); $appsLib =& CAppPlugins::getInstance(); $appsLib->loadApplications(); $params = array(); $params[] = $album; $url = $handler->getEditedAlbumURL($album->id); if ($album->delete()) { $appsLib->triggerEvent('onAfterAlbumDelete', $params); // @rule: remove from featured item if item is featured CFactory::load('libraries', 'featured'); $featured = new CFeatured(FEATURED_ALBUMS); $featured->delete($album->id); //add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint('album.remove'); // Remove from activity stream CActivityStream::remove('photos', $id); $mainframe =& JFactory::getApplication(); $task = !empty($task) ? '&task=' . $task : ''; $message = JText::sprintf('CC ALBUM REMOVED', $album->name); $mainframe->redirect($url, $message); } }
function deleteFromCommunityFeatured($user, $groups, $albums, $videos) { //delete featured user $featured = new CFeatured(FEATURED_USERS); if (!empty($user)) { $featured->delete($user['id']); } //delete featured groups $featured = new CFeatured(FEATURED_GROUPS); if (!empty($groups)) { $groupIds = explode(",", $groups); foreach ($groupIds as $groupId) { $featured->delete($groupId); } } //delete featured albums $featured = new CFeatured(FEATURED_ALBUMS); if (!empty($albums)) { foreach ($albums as $albumId) { $featured->delete($albumId); } } //delete featured albums $featured = new CFeatured(FEATURED_VIDEOS); if (!empty($videos)) { foreach ($videos as $videoId) { $featured->delete($videoId); } } }
/** * Delete featured videos * * @param int $id The id of the video * @return True on success * @since 1.2 * */ private function _deleteFeaturedVideos($id = 0) { if (!COwnerHelper::isRegisteredUser()) { return; } $featuredVideo = new CFeatured(FEATURED_VIDEOS); $featuredVideo->delete($id); return; }
/** * Delete featured videos * * @param int $id The id of the video * @return True on success * @since 1.2 **/ private function _deleteFeaturedVideos($id = 0) { if (!COwnerHelper::isRegisteredUser()) { return; } CFactory::load('libraries', 'featured'); $featuredVideo = new CFeatured(FEATURED_VIDEOS); $featuredVideo->delete($id); return; }
/** * Ajax function to delete a group * * @param $groupId The specific group id to unpublish **/ public function ajaxDeleteGroup($groupId, $step = 1) { $response = new JAXResponse(); CFactory::load('libraries', 'activities'); CFactory::load('helpers', 'owner'); CFactory::load('models', 'groups'); $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupModel = CFactory::getModel('groups'); $membersCount = $groupModel->getMembersCount($groupId); $my = CFactory::getUser(); $isMine = $my->id == $group->ownerid; if (!COwnerHelper::isCommunityAdmin() && !($isMine && $membersCount <= 1)) { $content = JText::_('CC NOT ALLOWED TO DELETE GROUP'); $buttons = '<input type="button" class="button" onclick="cWindowHide();" value="' . JText::_('CC CANCEL') . '"/>'; $response->addScriptCall('cWindowResize', 100); $response->addAssign('cWindowContent', 'innerHTML', $content); $response->addScriptCall('cWindowActions', $buttons); } else { $response->addScriptCall('cWindowResize', 160); $doneMessage = ' - <span class=\'success\'>' . JText::_('CC DONE') . '</span><br />'; $failedMessage = ' - <span class=\'failed\'>' . JText::_('CC FAILED') . '</span><br />'; switch ($step) { case 1: // Nothing gets deleted yet. Just show a messge to the next step if (empty($groupId)) { $content = JText::_('CC INVALID GROUP ID'); } else { $content = '<strong>' . JText::sprintf('CC DELETING GROUP', $group->name) . '</strong><br/>'; $content .= JText::_('CC DELETING GROUP BULLETIN'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 2);'); //trigger for onBeforeGroupDelete $this->triggerGroupEvents('onBeforeGroupDelete', $group); } $response->addAssign('cWindowContent', 'innerHTML', $content); break; case 2: // Delete all group bulletins if (CommunityModelGroups::deleteGroupBulletins($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('CC DELETING GROUP MEMBERS'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 3);'); break; case 3: // Delete all group members if (CommunityModelGroups::deleteGroupMembers($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('CC DELETING GROUP WALLS'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 4);'); break; case 4: // Delete all group wall if (CommunityModelGroups::deleteGroupWall($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('CC DELETING GROUP DISCUSSIONS'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 5);'); break; case 5: // Delete all group discussions if (CommunityModelGroups::deleteGroupDiscussions($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('CC DELETING GROUP MEDIA'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 6);'); break; case 6: // Delete all group's media files if (CommunityModelGroups::deleteGroupMedia($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 7);'); break; case 7: // Delete group $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupData = $group; if ($group->delete($groupId)) { CFactory::load('libraries', 'featured'); $featured = new CFeatured(FEATURED_GROUPS); $featured->delete($groupId); jimport('joomla.filesystem.file'); //@rule: Delete only thumbnail and avatars that exists for the specific group if ($groupData->avatar != "components/com_community/assets/group.jpg" && !empty($groupData->avatar)) { $path = explode('/', $groupData->avatar); $file = JPATH_ROOT . DS . $path[0] . DS . $path[1] . DS . $path[2] . DS . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } if ($groupData->thumb != "components/com_community/assets/group_thumb.jpg" && !empty($groupData->thumb)) { $path = explode('/', $groupData->thumb); $file = JPATH_ROOT . DS . $path[0] . DS . $path[1] . DS . $path[2] . DS . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } $html = '<div class=\\"info\\" style=\\"display: none;\\">' . JText::_('CC GROUP DELETED') . '</div>'; $response->addScriptCall('joms.jQuery("' . $html . '").prependTo("#community-wrap").fadeIn();'); $response->addScriptCall('joms.jQuery("#community-groups-wrap").fadeOut();'); $content = JText::_('CC GROUP DELETED'); //trigger for onGroupDelete $this->triggerGroupEvents('onAfterGroupDelete', $groupData); // Remove from activity stream CActivityStream::remove('groups', $groupId); } else { $content = JText::_('CC ERROR WHILE DELETING GROUP'); } $redirect = CRoute::_(JURI::root() . 'index.php?option=com_community&view=groups'); $buttons = '<input type="button" class="button" id="groupDeleteDone" onclick="cWindowHide(); window.location=\'' . $redirect . '\';" value="' . JText::_('Done') . '"/>'; $response->addAssign('cWindowContent', 'innerHTML', $content); $response->addScriptCall('cWindowActions', $buttons); $response->addScriptCall('cWindowResize', 100); break; default: break; } } return $response->sendResponse(); }
public function ajaxRemoveFeatured($eventId) { $filter = JFilterInput::getInstance(); $eventId = $filter->clean($eventId, 'int'); $json = array(); if (COwnerHelper::isCommunityAdmin()) { $model = CFactory::getModel('Featured'); //CFactory::load( 'libraries' , 'featured' ); $featured = new CFeatured(FEATURED_EVENTS); $my = CFactory::getUser(); if ($featured->delete($eventId)) { $json['success'] = true; $json['html'] = JText::_('COM_COMMUNITY_EVENT_REMOVED_FROM_FEATURED'); } else { $json['error'] = JText::_('COM_COMMUNITY_REMOVING_EVENT_FROM_FEATURED_ERROR'); } } else { $json['error'] = JText::_('COM_COMMUNITY_NOT_ALLOWED_TO_ACCESS_SECTION'); } //ClearCache in Featured List $this->cacheClean(array(COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_GROUPS)); die(json_encode($json)); }
/** * Ajax function to delete a group * * @param $groupId The specific group id to unpublish **/ public function ajaxDeleteGroup($groupId, $step = 1) { $filter = JFilterInput::getInstance(); $groupId = $filter->clean($groupId, 'int'); $step = $filter->clean($step, 'int'); $response = new JAXResponse(); CFactory::load('libraries', 'activities'); CFactory::load('helpers', 'owner'); CFactory::load('models', 'groups'); $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupModel = CFactory::getModel('groups'); $membersCount = $groupModel->getMembersCount($groupId); $my = CFactory::getUser(); // @rule: Do not allow anyone that tries to be funky! if (!$my->authorise('community.delete', 'groups.' . $groupId, $group)) { $content = JText::_('COM_COMMUNITY_GROUPS_NOT_ALLOWED_DELETE'); $buttons = '<input type="button" class="button" onclick="cWindowHide();" value="' . JText::_('COM_COMMUNITY_CANCEL') . '"/>'; $response->addScriptCall('cWindowAddContent', $content, $buttons); return $response->sendResponse(); } $doneMessage = ' - <span class=\'success\'>' . JText::_('COM_COMMUNITY_DONE') . '</span><br />'; $failedMessage = ' - <span class=\'failed\'>' . JText::_('COM_COMMUNITY_FAILED') . '</span><br />'; $childId = 0; switch ($step) { case 1: // Nothing gets deleted yet. Just show a messge to the next step if (empty($groupId)) { $content = JText::_('COM_COMMUNITY_GROUPS_ID_NOITEM'); } else { $content = '<strong>' . JText::sprintf('COM_COMMUNITY_GROUPS_DELETE_GROUP', $group->name) . '</strong><br/>'; $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_BULLETIN'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 2);'); //trigger for onBeforeGroupDelete $this->triggerGroupEvents('onBeforeGroupDelete', $group); } $response->addScriptCall('cWindowAddContent', $content); break; case 2: CommunityModelGroups::getGroupChildId($groupId); // Delete all group bulletins if (CommunityModelGroups::deleteGroupBulletins($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_GROUP_MEMBERS'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 3);'); break; case 3: // Delete all group members if (CommunityModelGroups::deleteGroupMembers($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_WALLS_DELETE'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 4);'); break; case 4: // Delete all group wall if (CommunityModelGroups::deleteGroupWall($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DISCUSSIONS_DELETEL'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 5);'); break; case 5: // Delete all group discussions if (CommunityModelGroups::deleteGroupDiscussions($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_MEDIA'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 6);'); break; case 6: // Delete all group's media files if (CommunityModelGroups::deleteGroupMedia($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 7);'); break; case 7: // Delete group $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupData = $group; if ($group->delete($groupId)) { CFactory::load('libraries', 'featured'); $featured = new CFeatured(FEATURED_GROUPS); $featured->delete($groupId); jimport('joomla.filesystem.file'); //@rule: Delete only thumbnail and avatars that exists for the specific group if ($groupData->avatar != "components/com_community/assets/group.jpg" && !empty($groupData->avatar)) { $path = explode('/', $groupData->avatar); $file = JPATH_ROOT . DS . $path[0] . DS . $path[1] . DS . $path[2] . DS . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } if ($groupData->thumb != "components/com_community/assets/group_thumb.jpg" && !empty($groupData->thumb)) { $path = explode('/', $groupData->thumb); $file = JPATH_ROOT . DS . $path[0] . DS . $path[1] . DS . $path[2] . DS . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } $html = '<div class=\\"info\\" style=\\"display: none;\\">' . JText::_('COM_COMMUNITY_GROUPS_DELETED') . '</div>'; $response->addScriptCall('joms.jQuery("' . $html . '").prependTo("#community-wrap").fadeIn();'); $response->addScriptCall('joms.jQuery("#community-groups-wrap").fadeOut();'); $content = JText::_('COM_COMMUNITY_GROUPS_DELETED'); //trigger for onGroupDelete $this->triggerGroupEvents('onAfterGroupDelete', $groupData); } else { $content = JText::_('COM_COMMUNITY_GROUPS_DELETE_ERROR'); } $redirect = CRoute::_(JURI::root() . 'index.php?option=com_community&view=groups'); $buttons = '<input type="button" class="button" id="groupDeleteDone" onclick="cWindowHide(); window.location=\'' . $redirect . '\';" value="' . JText::_('COM_COMMUNITY_DONE_BUTTON') . '"/>'; $response->addScriptCall('cWindowAddContent', $content, $buttons); break; default: break; } //Clear Cache for groups $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_GROUPS, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_GROUPS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); return $response->sendResponse(); }
/** * Ajax function to delete a group * * @param $groupId The specific group id to unpublish * */ public function ajaxDeleteGroup($groupId, $step = 1) { $filter = JFilterInput::getInstance(); $groupId = $filter->clean($groupId, 'int'); $step = $filter->clean($step, 'int'); $json = array(); $response = new JAXResponse(); $group = JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupModel = CFactory::getModel('groups'); $membersCount = $groupModel->getMembersCount($groupId); $my = CFactory::getUser(); // @rule: Do not allow anyone that tries to be funky! if (!$my->authorise('community.delete', 'groups.' . $groupId, $group)) { $json['error'] = JText::_('COM_COMMUNITY_GROUPS_NOT_ALLOWED_DELETE'); die(json_encode($json)); } $doneMessage = ' - <span class=\'success\'>' . JText::_('COM_COMMUNITY_DONE') . '</span><br />'; $failedMessage = ' - <span class=\'failed\'>' . JText::_('COM_COMMUNITY_FAILED') . '</span><br />'; $childId = 0; switch ($step) { case 1: // Nothing gets deleted yet. Just show a messge to the next step if (empty($groupId)) { $json['error'] = JText::_('COM_COMMUNITY_GROUPS_ID_NOITEM'); } else { $json['message'] = '<strong>' . JText::sprintf('COM_COMMUNITY_GROUPS_DELETE_GROUP', $group->name) . '</strong><br/>'; $json['message'] .= JText::_('COM_COMMUNITY_GROUPS_DELETE_BULLETIN'); $json['next'] = 2; //trigger for onBeforeGroupDelete $this->triggerGroupEvents('onBeforeGroupDelete', $group); } break; case 2: // Delete all group bulletins CommunityModelGroups::getGroupChildId($groupId); if (CommunityModelGroups::deleteGroupBulletins($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_GROUP_MEMBERS'); $json['message'] = $content; $json['next'] = 3; break; case 3: // Delete all group members if (CommunityModelGroups::deleteGroupMembers($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_WALLS_DELETE'); $json['message'] = $content; $json['next'] = 4; break; case 4: // Delete all group wall if (CommunityModelGroups::deleteGroupWall($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DISCUSSIONS_DELETEL'); $json['message'] = $content; $json['next'] = 5; break; case 5: // Delete all group discussions if (CommunityModelGroups::deleteGroupDiscussions($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_MEDIA'); $json['message'] = $content; $json['next'] = 6; break; case 6: // Delete all group's media files if (CommunityModelGroups::deleteGroupMedia($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $json['message'] = $content; $json['next'] = 7; break; case 7: // Delete group $group = JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupData = $group; if ($group->delete($groupId)) { //CFactory::load( 'libraries' , 'featured' ); $featured = new CFeatured(FEATURED_GROUPS); $featured->delete($groupId); jimport('joomla.filesystem.file'); //@rule: Delete only thumbnail and avatars that exists for the specific group if ($groupData->avatar != "components/com_community/assets/group.jpg" && !empty($groupData->avatar)) { $path = explode('/', $groupData->avatar); $file = JPATH_ROOT . '/' . $path[0] . '/' . $path[1] . '/' . $path[2] . '/' . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } if ($groupData->thumb != "components/com_community/assets/group_thumb.jpg" && !empty($groupData->thumb)) { $path = explode('/', $groupData->thumb); $file = JPATH_ROOT . '/' . $path[0] . '/' . $path[1] . '/' . $path[2] . '/' . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } $content = JText::_('COM_COMMUNITY_GROUPS_DELETED'); //trigger for onGroupDelete $this->triggerGroupEvents('onAfterGroupDelete', $groupData); } else { $content = JText::_('COM_COMMUNITY_GROUPS_DELETE_ERROR'); } $redirect = CRoute::_('index.php?option=com_community&view=groups'); $json['message'] = $content; $json['redirect'] = $redirect; $json['btnDone'] = JText::_('COM_COMMUNITY_DONE_BUTTON'); break; default: break; } //Clear Cache for groups $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_GROUPS, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_GROUPS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); die(json_encode($json)); // return $response->sendResponse(); }