AU_anonymous_comments = true) is set to differentiate just in case someone decided * to take our username. */ function set_anonymous_user() { //first see if a user has been created previously $users = elgg_get_entities_from_metadata(array( 'types' => 'user', 'metadata_name' => 'AU_anonymous_comments', 'value' => true, )); if (!$users) { //no previous user - create a new one //find available username $i = 1; $username = "AU_anonymous_comments_user1"; $basename = "AU_anonymous_comments_user"; while (get_user_by_username($username)) { $i++; $username = $basename . $i; } //let's make a user $anon_user = new \ElggUser(); $anon_user->username = $username; $anon_user->email = "AU_anonymous_comments_user" . $i . "@example.com"; $anon_user->name = elgg_echo('AU_anonymous_comments:display_name'); $anon_user->access_id = ACCESS_PUBLIC; $anon_user->salt = ''; $anon_user->password = ''; // doesn't need to match, we don't want people logging in anyway $anon_user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created. $anon_user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created. $anon_user->save(); // set the plugin-identifiable metadata $anon_user->AU_anonymous_comments = true; } else { // we found our user through metadata $anon_user = $users[0]; } elgg_set_plugin_setting('anon_guid', $anon_user->guid, PLUGIN_ID); return $anon_user; } /** * this function returns true if the entity is being moderated * * @param type $id * @return boolean */ function is_moderated($entity) { if (!elgg_instanceof($entity)) { return false; } if ($entity->is_moderated) { return true; } // this check is necessary in case there's a way to set public content as unmoderated // then is_moderated can === 0 if ($entity->access_id == ACCESS_PUBLIC && is_null($entity->is_moderated)) { return true; } return false; } /** * generate a hard-to-guess token for offline approval/rejection * * @param type $comment * @return type */ function get_token($comment) { if ($comment->__anonymous_comment_token) { return $comment->__anonymous_comment_token; } // generate a token for this comment $token = sha1(uniqid('auac' . $comment->guid)); $comment->__anonymous_comment_token = $token; return $token; }