public function actionIndex()
 {
     $keyword = Yii::$app->request->get('keyword', "");
     $scope = Yii::$app->request->get('scope', "");
     $page = (int) Yii::$app->request->get('page', 1);
     $limitSpaceGuids = Yii::$app->request->get('limitSpaceGuids', "");
     $limitSpaces = array();
     if ($limitSpaceGuids !== "") {
         foreach (explode(",", $limitSpaceGuids) as $guid) {
             $guid = trim($guid);
             if ($guid != "") {
                 $space = Space::findOne(['guid' => trim($guid)]);
                 if ($space !== null) {
                     $limitSpaces[] = $space;
                 }
             }
         }
     }
     $options = ['page' => $page, 'sort' => $keyword == '' ? 'title' : null, 'pageSize' => Yii::$app->settings->get('paginationSize'), 'limitSpaces' => $limitSpaces];
     if ($scope == self::SCOPE_CONTENT) {
         $options['type'] = \humhub\modules\search\engine\Search::DOCUMENT_TYPE_CONTENT;
     } elseif ($scope == self::SCOPE_SPACE) {
         $options['model'] = Space::className();
     } elseif ($scope == self::SCOPE_USER) {
         $options['model'] = User::className();
     } else {
         $scope = self::SCOPE_ALL;
     }
     $searchResultSet = Yii::$app->search->find($keyword, $options);
     $pagination = new \yii\data\Pagination();
     $pagination->totalCount = $searchResultSet->total;
     $pagination->pageSize = $searchResultSet->pageSize;
     return $this->render('index', array('scope' => $scope, 'keyword' => $keyword, 'results' => $searchResultSet->getResultInstances(), 'pagination' => $pagination, 'totals' => $this->getTotals($keyword, $options), 'limitSpaceGuids' => $limitSpaceGuids));
 }
Exemple #2
0
 /**
  * Gets a space setting
  * 
  * @see \humhub\modules\content\components\ContentContainerSettingsManager::get
  * @param int $spaceId
  * @param string $name
  * @param string $moduleId
  * @param string $defaultValue
  * @return string
  */
 public static function Get($space, $name, $moduleId = "", $defaultValue = "")
 {
     $user = Space::findOne(['id' => $space]);
     $value = self::getModule($moduleId)->settings->contentContainer($user)->get($name);
     if ($value === null) {
         return $defaultValue;
     }
     return $value;
 }
Exemple #3
0
 /**
  * Gets space url name by given guid
  * 
  * @param string $guid
  * @return string|null the space url part
  */
 public static function getUrlBySpaceGuid($guid)
 {
     if (isset(static::$spaceUrlMap[$guid])) {
         return static::$spaceUrlMap[$guid];
     }
     $space = Space::findOne(['guid' => $guid]);
     if ($space !== null) {
         static::$spaceUrlMap[$space->guid] = $space->url != '' ? $space->url : $space->guid;
         return static::$spaceUrlMap[$space->guid];
     }
     return null;
 }
 public function testGetFollowers()
 {
     Yii::$app->user->switchIdentity(User::findOne(['id' => 1]));
     $space = Space::findOne(['id' => 3]);
     $space->follow(1);
     $space->follow(2);
     $space->follow(3);
     $users = $space->getFollowers();
     $userIds = array_map(create_function('$user', 'return $user->id;'), $users);
     sort($userIds);
     $this->assertEquals(array(1, 2, 3), $userIds);
 }
 /**
  * This validator function checks the defaultSpaceGuid.
  *
  * @param type $attribute
  * @param type $params
  */
 public function checkSpaceGuid($attribute, $params)
 {
     if ($this->defaultSpaceGuid != "") {
         foreach (explode(',', $this->defaultSpaceGuid) as $spaceGuid) {
             if ($spaceGuid != "") {
                 $space = \humhub\modules\space\models\Space::findOne(array('guid' => $spaceGuid));
                 if ($space == null) {
                     $this->addError($attribute, Yii::t('AdminModule.forms_BasicSettingsForm', "Invalid space"));
                 }
             }
         }
     }
 }
Exemple #6
0
 /**
  * Tests spaces which automatically adds new members
  * Fixture Space 3
  */
 public function testAutoAddSpace()
 {
     $space2 = Space::findOne(['id' => 2]);
     $space3 = Space::findOne(['id' => 3]);
     $user = new User();
     $user->username = "******";
     $user->email = "*****@*****.**";
     $this->assertTrue($user->save());
     $this->assertFalse($space2->isMember($user->id));
     // not assigned
     $this->assertTrue($space3->isMember($user->id));
     // via global assign
 }
 /**
  * Returns the current selected space by parameter guid
  *
  * If space doesnt exists or there a no permissions and exception
  * will thrown.
  *
  * @return Space
  * @throws HttpException
  */
 public function getSpace()
 {
     if ($this->space != null) {
         return $this->space;
     }
     // Get Space GUID by parameter
     $guid = Yii::$app->request->get('sguid');
     // Try Load the space
     $this->space = Space::findOne(['guid' => $guid]);
     if ($this->space == null) {
         throw new HttpException(404, Yii::t('SpaceModule.behaviors_SpaceControllerBehavior', 'Space not found!'));
     }
     $this->checkAccess();
     return $this->space;
 }
 public function actionDeleteContent()
 {
     $this->forcePostRequest();
     $model = Yii::$app->request->get('model');
     $id = Yii::$app->request->get('id');
     $content = Content::get($model, $id);
     if ($content->content->canDelete()) {
         $content->delete();
     }
     if (!$content->content->space_id) {
         return $this->htmlRedirect(Url::to(['/reportcontent/admin']));
     } else {
         $space = Space::findOne(['id' => $content->content->space_id]);
         return $this->htmlRedirect($space->createUrl('/reportcontent/space-admin'));
     }
 }
 /**
  * Returns a List of Users
  */
 public function actionBasic()
 {
     $form = new \humhub\modules\admin\models\forms\BasicSettingsForm();
     $form->name = Setting::Get('name');
     $form->baseUrl = Setting::Get('baseUrl');
     $form->defaultLanguage = Setting::Get('defaultLanguage');
     $form->timeZone = Setting::Get('timeZone');
     $form->dashboardShowProfilePostForm = Setting::Get('showProfilePostForm', 'dashboard');
     $form->tour = Setting::Get('enable', 'tour');
     $form->share = Setting::Get('enable', 'share');
     $form->defaultSpaceGuid = "";
     foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $defaultSpace) {
         $form->defaultSpaceGuid .= $defaultSpace->guid . ",";
     }
     if ($form->load(Yii::$app->request->post()) && $form->validate()) {
         Setting::Set('name', $form->name);
         Setting::Set('baseUrl', $form->baseUrl);
         Setting::Set('defaultLanguage', $form->defaultLanguage);
         Setting::Set('timeZone', $form->timeZone);
         Setting::Set('enable', $form->tour, 'tour');
         Setting::Set('enable', $form->share, 'share');
         Setting::Set('showProfilePostForm', $form->dashboardShowProfilePostForm, 'dashboard');
         $spaceGuids = explode(",", $form->defaultSpaceGuid);
         // Remove Old Default Spaces
         foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $space) {
             if (!in_array($space->guid, $spaceGuids)) {
                 $space->auto_add_new_members = 0;
                 $space->save();
             }
         }
         // Add new Default Spaces
         foreach ($spaceGuids as $spaceGuid) {
             $space = \humhub\modules\space\models\Space::findOne(['guid' => $spaceGuid]);
             if ($space != null && $space->auto_add_new_members != 1) {
                 $space->auto_add_new_members = 1;
                 $space->save();
             }
         }
         DynamicConfig::rewrite();
         // set flash message
         Yii::$app->getSession()->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved'));
         return Yii::$app->response->redirect(Url::toRoute('/admin/setting/basic'));
     }
     return $this->render('basic', array('model' => $form));
 }
 /** 
  * Registers a user
  * @param $data
  * @return Bool
  */
 private function registerUser($data)
 {
     $userModel = new User();
     $userModel->scenario = 'registration';
     $profileModel = $userModel->profile;
     $profileModel->scenario = 'registration';
     // User: Set values
     $userModel->username = $data['username'];
     $userModel->email = $data['email'];
     $userModel->group_id = $data['group_id'];
     $userModel->status = User::STATUS_ENABLED;
     // Profile: Set values
     $profileModel->firstname = $data['firstname'];
     $profileModel->lastname = $data['lastname'];
     // Password: Set values
     $userPasswordModel = new Password();
     $userPasswordModel->setPassword($data['password']);
     if ($userModel->save()) {
         // Save user profile
         $profileModel->user_id = $userModel->id;
         $profileModel->save();
         // Save user password
         $userPasswordModel->user_id = $userModel->id;
         $userPasswordModel->save();
         // Join space / create then join space
         foreach ($data['space_names'] as $key => $space_name) {
             // Find space by name attribute
             $space = Space::findOne(['name' => $space_name]);
             // Create the space if not found
             if ($space == null) {
                 $space = new Space();
                 $space->name = $space_name;
                 $space->save();
             }
             // Add member into space
             $space->addMember($userModel->id);
         }
         return true;
     } else {
         Yii::$app->session->setFlash('error', Html::errorSummary($userModel));
         return false;
     }
 }
 /**
  * This is a special case, because we need to find a space to start the tour
  */
 public function actionStartSpaceTour()
 {
     $space = null;
     // Loop over all spaces where the user is member
     foreach (\humhub\modules\space\models\Membership::GetUserSpaces() as $space) {
         if ($space->isAdmin()) {
             // If user is admin on this space, it´s the perfect match
             break;
         }
     }
     if ($space === null) {
         // If user is not member of any space, try to find a public space
         // to run tour in
         $space = Space::findOne(['!=', 'visibility' => Space::VISIBILITY_NONE]);
     }
     if ($space === null) {
         throw new HttpException(404, 'Could not find any public space to run tour!');
     }
     return $this->redirect($space->createUrl('/space/space', array('tour' => true)));
 }
 public function testPublicContent()
 {
     $this->becomeUser('User2');
     $space = Space::findOne(['id' => 2]);
     $post1 = new Post();
     $post1->message = "Private Post";
     $post1->content->setContainer($space);
     $post1->content->visibility = Content::VISIBILITY_PRIVATE;
     $post1->save();
     $w1 = $post1->content->getFirstWallEntryId();
     $post2 = new Post();
     $post2->message = "Public Post";
     $post2->content->setContainer($space);
     $post2->content->visibility = Content::VISIBILITY_PUBLIC;
     $post2->save();
     $w2 = $post2->content->getFirstWallEntryId();
     $this->becomeUser('Admin');
     $ids = $this->getStreamActionIds($space, 2);
     $this->assertFalse(in_array($w1, $ids));
     $this->assertTrue(in_array($w2, $ids));
 }
Exemple #13
0
 /**
  * Displays / Run the Widgets
  */
 public function run()
 {
     // Try to get current field value, when model & attribute attributes are specified.
     if ($this->model != null && $this->attribute != null) {
         $attribute = $this->attribute;
         $this->value = $this->model->{$attribute};
     }
     if ($this->spaceSearchUrl == "") {
         $this->spaceSearchUrl = \yii\helpers\Url::to(['/space/browse/search-json', 'keyword' => '-keywordPlaceholder-']);
     }
     if ($this->placeholder === null) {
         $this->placeholder = Yii::t('SpaceModule.picker', 'Add {n,plural,=1{space} other{spaces}}', ['n' => $this->maxSpaces]);
     }
     // Currently populated spaces
     $spaces = [];
     foreach (explode(",", $this->value) as $guid) {
         $space = Space::findOne(['guid' => trim($guid)]);
         if ($space != null) {
             $spaces[] = $space;
         }
     }
     return $this->render('spacePicker', array('spaceSearchUrl' => $this->spaceSearchUrl, 'maxSpaces' => $this->maxSpaces, 'value' => $this->value, 'spaces' => $spaces, 'placeholder' => $this->placeholder, 'inputId' => $this->inputId));
 }
 public function actionAssignAllMembers($spaceId)
 {
     $space = Space::findOne(['id' => $spaceId]);
     if ($space == null) {
         print "Error: Space not found! Check id!\n\n";
         return;
     }
     $countMembers = 0;
     $countAssigns = 0;
     $this->stdout("\nAdding Members:\n\n");
     foreach (User::find()->where(['status' => User::STATUS_ENABLED])->all() as $user) {
         if ($space->isMember($user->id)) {
             $countMembers++;
         } else {
             $this->stdout("\t" . $user->displayName . " added. \n", Console::FG_YELLOW);
             #Yii::app()->user->setId($user->id);
             Yii::$app->user->switchIdentity($user);
             $space->addMember($user->id);
             $countAssigns++;
         }
     }
     $this->stdout("\nAdded " . $countAssigns . " new members to space " . $space->name . "\n", Console::FG_GREEN);
 }
Exemple #15
0
 /**
  * Checks if this content can readed
  *
  * @param type $userId
  * @return type
  */
 public function canRead($userId = "")
 {
     if ($userId == "") {
         $userId = Yii::$app->user->id;
     }
     // For guests users
     if (Yii::$app->user->isGuest) {
         if ($this->visibility == 1) {
             if ($this->container instanceof Space) {
                 if ($this->container->visibility == Space::VISIBILITY_ALL) {
                     return true;
                 }
             } elseif ($this->container instanceof User) {
                 if ($this->container->visibility == User::VISIBILITY_ALL) {
                     return true;
                 }
             }
         }
         return false;
     }
     if ($this->visibility == 0) {
         // Space/User Content Access Check
         if ($this->space_id != "") {
             $space = null;
             if (isset(Yii::$app->params['currentSpace']) && Yii::$app->params['currentSpace']->id == $this->space_id) {
                 $space = Yii::$app->params['currentSpace'];
             } else {
                 $space = Space::findOne(['id' => $this->space_id]);
             }
             // Space Found
             if ($space != null) {
                 if (!$space->isMember($userId)) {
                     return false;
                 }
             }
         } else {
             // Check for user content
             if ($userId != $this->user_id) {
                 return false;
             }
         }
     }
     return true;
 }
Exemple #16
0
 /**
  * Translate guids from users to username
  *
  * @param strint $text Contains the complete message
  * @param boolean $buildAnchors Wrap the username with a link to the profile, if it's true
  */
 public static function translateMentioning($text, $buildAnchors = true)
 {
     return preg_replace_callback('@\\@\\-([us])([\\w\\-]*?)($|\\s|\\.|")@', function ($hit) use(&$buildAnchors) {
         if ($hit[1] == 'u') {
             $user = \humhub\modules\user\models\User::findOne(['guid' => $hit[2]]);
             if ($user !== null) {
                 if ($buildAnchors) {
                     return ' <span contenteditable="false"><a href="' . $user->getUrl() . '" target="_self" class="atwho-user" data-user-guid="@-u' . $user->guid . '">@' . Html::encode($user->getDisplayName()) . '</a></span>' . $hit[3];
                 }
                 return " @" . Html::encode($user->getDisplayName()) . $hit[3];
             }
         } elseif ($hit[1] == 's') {
             $space = \humhub\modules\space\models\Space::findOne(['guid' => $hit[2]]);
             if ($space !== null) {
                 if ($buildAnchors) {
                     return ' <span contenteditable="false"><a href="' . $space->getUrl() . '" target="_self" class="atwho-user" data-user-guid="@-s' . $space->guid . '">@' . Html::encode($space->name) . '</a></span>' . $hit[3];
                 }
                 return " @" . Html::encode($space->name) . $hit[3];
             }
         }
         return $hit[0];
     }, $text);
 }
 /**
  * Creates the given ContentActiveRecord based on given submitted form information.
  * 
  * - Automatically assigns ContentContainer
  * - Access Check
  * - User Notification / File Uploads
  * - Reloads Wall after successfull creation or returns error json
  * 
  * [See guide section](guide:dev-module-stream.md#CreateContentForm)
  * 
  * @param ContentActiveRecord $record
  * @return string json 
  */
 public static function create(ContentActiveRecord $record)
 {
     Yii::$app->response->format = 'json';
     // Set Content Container
     $contentContainer = null;
     $containerClass = Yii::$app->request->post('containerClass');
     $containerGuid = Yii::$app->request->post('containerGuid', "");
     if ($containerClass === User::className()) {
         $contentContainer = User::findOne(['guid' => $containerGuid]);
         $record->content->visibility = 1;
     } elseif ($containerClass === Space::className()) {
         $contentContainer = Space::findOne(['guid' => $containerGuid]);
         $record->content->visibility = Yii::$app->request->post('visibility');
     }
     $record->content->container = $contentContainer;
     // Handle Notify User Features of ContentFormWidget
     // ToDo: Check permissions of user guids
     $userGuids = Yii::$app->request->post('notifyUserInput');
     if ($userGuids != "") {
         foreach (explode(",", $userGuids) as $guid) {
             $user = User::findOne(['guid' => trim($guid)]);
             if ($user) {
                 $record->content->notifyUsersOfNewContent[] = $user;
             }
         }
     }
     // Store List of attached Files to add them after Save
     $record->content->attachFileGuidsAfterSave = Yii::$app->request->post('fileList');
     if ($record->validate() && $record->save()) {
         return array('wallEntryId' => $record->content->getFirstWallEntryId());
     }
     return array('errors' => $record->getErrors());
 }
 /**
  * Saves the form
  *
  * @return boolean
  */
 public function save()
 {
     Yii::$app->settings->set('name', $this->name);
     Yii::$app->settings->set('baseUrl', $this->baseUrl);
     Yii::$app->settings->set('defaultLanguage', $this->defaultLanguage);
     Yii::$app->settings->set('timeZone', $this->timeZone);
     Yii::$app->getModule('dashboard')->settings->set('showProfilePostForm', $this->dashboardShowProfilePostForm);
     Yii::$app->getModule('tour')->settings->set('enable', $this->tour);
     Yii::$app->getModule('friendship')->settings->set('enable', $this->enableFriendshipModule);
     Yii::$app->getModule('content')->settings->set('stream.defaultSort', $this->defaultStreamSort);
     $spaceGuids = explode(",", $this->defaultSpaceGuid);
     // Remove Old Default Spaces
     foreach (Space::findAll(['auto_add_new_members' => 1]) as $space) {
         if (!in_array($space->guid, $spaceGuids)) {
             $space->auto_add_new_members = 0;
             $space->save();
         }
     }
     // Add new Default Spaces
     foreach ($spaceGuids as $spaceGuid) {
         $space = Space::findOne(['guid' => $spaceGuid]);
         if ($space != null && $space->auto_add_new_members != 1) {
             $space->auto_add_new_members = 1;
             $space->save();
         }
     }
     DynamicConfig::rewrite();
     return true;
 }
Exemple #19
0
 * @property String $spaceSearchUrl the url of the search, to find the spaces
 * @property String $currentValue is the current value of the parent field.
 *
 * @package humhub.modules_core.user
 * @since 0.5
 */
use yii\helpers\Html;
use humhub\modules\space\models\Space;
$this->registerJsFile('@web/resources/space/spacepicker.js', ['position' => \yii\web\View::POS_END]);
?>

<?php 
// Resolve guids to space tags
$newValue = "";
foreach (explode(",", $currentValue) as $guid) {
    $space = Space::findOne(['guid' => trim($guid)]);
    if ($space != null) {
        $imageUrl = $space->getProfileImage()->getUrl();
        $name = Html::encode($space->name);
        $newValue .= '<li class="spaceInput" id="' . $space->guid . '"><img class="img-rounded" alt="24x24" data-src="holder.js/24x24" style="width: 24px; height: 24px;" src="' . $imageUrl . '" alt="' . $name . 'r" width="24" height="24">' . addslashes($name) . '<i class="fa fa-times-circle"></i></li>';
    }
}
?>


<script type="text/javascript">

    $(function() {
        $('#<?php 
echo $inputId;
?>
Exemple #20
0
 public function setUpApproved()
 {
     $userInvite = Invite::findOne(['email' => $this->email]);
     if ($userInvite !== null) {
         // User was invited to a space
         if ($userInvite->source == Invite::SOURCE_INVITE) {
             $space = \humhub\modules\space\models\Space::findOne(['id' => $userInvite->space_invite_id]);
             if ($space != null) {
                 $space->addMember($this->id);
             }
         }
         // Delete/Cleanup Invite Entry
         $userInvite->delete();
     }
     // Auto Assign User to the Group Space
     $group = Group::findOne(['id' => $this->group_id]);
     if ($group != null && $group->space_id != "") {
         $space = \humhub\modules\space\models\Space::findOne(['id' => $group->space_id]);
         if ($space !== null) {
             $space->addMember($this->id);
         }
     }
     // Auto Add User to the default spaces
     foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $space) {
         $space->addMember($this->id);
     }
     // Create new wall record for this user
     $wall = new \humhub\modules\content\models\Wall();
     $wall->object_model = $this->className();
     $wall->object_id = $this->id;
     $wall->save();
     $this->wall_id = $wall->id;
     $this->update(false, ['wall_id']);
 }
Exemple #21
0
 public function setUpApproved()
 {
     $userInvite = Invite::findOne(['email' => $this->email]);
     if ($userInvite !== null) {
         // User was invited to a space
         if ($userInvite->source == Invite::SOURCE_INVITE) {
             $space = \humhub\modules\space\models\Space::findOne(['id' => $userInvite->space_invite_id]);
             if ($space != null) {
                 $space->addMember($this->id);
             }
         }
         // Delete/Cleanup Invite Entry
         $userInvite->delete();
     }
     // Auto Assign User to the Group Space
     /* $group = Group::findOne(['id' => $this->group_id]);
        if ($group != null && $group->space_id != "") {
        $space = \humhub\modules\space\models\Space::findOne(['id' => $group->space_id]);
        if ($space !== null) {
        $space->addMember($this->id);
        }
        } */
     // Auto Add User to the default spaces
     foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $space) {
         $space->addMember($this->id);
     }
 }
Exemple #22
0
 public function populateDefaultSpaceGuid()
 {
     $defaultSpace = Space::findOne(['id' => $this->space_id]);
     if ($defaultSpace !== null) {
         $this->defaultSpaceGuid = $defaultSpace->guid;
     }
 }
 /**
  * Automatically loads the underlying contentContainer (User/Space) by using
  * the uguid/sguid request parameter
  *
  * @return boolean
  */
 public function init()
 {
     $spaceGuid = Yii::$app->request->get('sguid', '');
     $userGuid = Yii::$app->request->get('uguid', '');
     if ($spaceGuid != "") {
         $this->contentContainer = Space::findOne(['guid' => $spaceGuid]);
         if ($this->contentContainer == null) {
             throw new \yii\web\HttpException(404, Yii::t('base', 'Space not found!'));
         }
         $this->attachBehavior('SpaceControllerBehavior', array('class' => \humhub\modules\space\behaviors\SpaceController::className(), 'space' => $this->contentContainer));
         $this->subLayout = "@humhub/modules/space/views/space/_layout";
     } elseif ($userGuid != "") {
         $this->contentContainer = User::findOne(['guid' => $userGuid]);
         if ($this->contentContainer == null) {
             throw new \yii\web\HttpException(404, Yii::t('base', 'User not found!'));
         }
         $this->attachBehavior('ProfileControllerBehavior', ['class' => \humhub\modules\user\behaviors\ProfileController::className(), 'user' => $this->contentContainer]);
         $this->subLayout = "@humhub/modules/user/views/profile/_layout";
     } else {
         throw new \yii\web\HttpException(500, Yii::t('base', 'Could not determine content container!'));
     }
     /**
      * Auto check access rights to this container
      */
     if ($this->contentContainer != null) {
         if ($this->autoCheckContainerAccess) {
             $this->checkContainerAccess();
         }
     }
     if (!$this->checkModuleIsEnabled()) {
         throw new HttpException(405, Yii::t('base', 'Module is not enabled on this content container!'));
     }
     return parent::init();
 }