Skip to content

Commit

Permalink
add Profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jun 30, 2018
1 parent fe7a5b7 commit a5e03b9
Show file tree
Hide file tree
Showing 12 changed files with 910 additions and 0 deletions.
37 changes: 37 additions & 0 deletions addons/plugins/Profiles/.gitignore
@@ -0,0 +1,37 @@
.buildpath
.project
.settings
.htaccess

# Compiled source
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases
*.log
*.sql
*.sqlite

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
*~
85 changes: 85 additions & 0 deletions addons/plugins/Profiles/ProfileFieldModel.class.php
@@ -0,0 +1,85 @@
<?php
// Copyright 2014 Toby Zerner, Simon Zerner
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

class ProfileFieldModel extends ETModel {

public function __construct()
{
parent::__construct("profile_field", "fieldId");
}

public function getWithSQL($sql)
{
return $sql
->select("f.*")
->from("profile_field f")
->orderBy("f.position ASC")
->exec()
->allRows();
}

public function getData($memberId)
{
$sql = ET::SQL()
->select("d.data")
->from("profile_data d", "d.fieldId=f.fieldId AND d.memberId=:memberId", "left")
->bind(":memberId", $memberId);

return $this->getWithSQL($sql);
}

public function setData($memberId, $fieldId, $data)
{
ET::SQL()
->insert("profile_data")
->set("memberId", $memberId)
->set("fieldId", $fieldId)
->set("data", $data)
->setOnDuplicateKey("data", $data)
->exec();
}

public function delete($wheres = array())
{
return ET::SQL()
->delete("f, d")
->from("profile_field f")
->from("profile_data d", "f.fieldId=d.fieldId", "left")
->where($wheres)
->exec();
}

public function deleteById($id)
{
return $this->delete(array("f.fieldId" => $id));
}

public function update($values, $wheres = array())
{
if (in_array($values["type"], array("select", "radios", "checkboxes")))
$this->validate("options", $values["options"], array($this, "validateOptions"));

if ($this->errorCount()) return false;

return parent::update($values, $wheres);
}

public function create($values, $wheres = array())
{
if (in_array($values["type"], array("select", "radios", "checkboxes")))
$this->validate("options", $values["options"], array($this, "validateOptions"));

if ($this->errorCount()) return false;

return parent::create($values);
}

public function validateOptions($options)
{
$options = trim($options);
if (!strlen($options)) return "empty";
}
}
144 changes: 144 additions & 0 deletions addons/plugins/Profiles/ProfilesAdminController.class.php
@@ -0,0 +1,144 @@
<?php
// Copyright 2014 Toby Zerner, Simon Zerner
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

class ProfilesAdminController extends ETAdminController {

protected function model()
{
return ET::getInstance("profileFieldModel");
}

protected function plugin()
{
return ET::$plugins["Profiles"];
}

public function action_index()
{
$fields = $this->model()->get();

$this->addCSSFile($this->plugin()->resource("admin.css"));

$this->addJSFile("core/js/lib/jquery.ui.js");
$this->addJSFile($this->plugin()->resource("admin.js"));
$this->addJSLanguage("message.confirmDelete");

$this->data("fields", $fields);
$this->render($this->plugin()->view("admin/fields"));
}

public function action_edit($fieldId = "")
{
// Get this field's details. If it doesn't exist, show an error.
if (!($field = $this->model()->getById((int)$fieldId))) {
$this->render404();
return;
}

// Set up the form.
$form = ETFactory::make("form");
$form->action = URL("admin/profiles/edit/".$field["fieldId"]);
$form->setValues($field);

// Was the cancel button pressed?
if ($form->isPostBack("cancel")) $this->redirect(URL("admin/profiles"));

// Was the save button pressed?
if ($form->validPostBack("save")) {

$data = array(
"name" => $form->getValue("name"),
"description" => $form->getValue("description"),
"type" => $form->getValue("type"),
"options" => $form->getValue("options"),
"showOnPosts" => (bool)$form->getValue("showOnPosts"),
"hideFromGuests" => (bool)$form->getValue("hideFromGuests"),
"searchable" => (bool)$form->getValue("searchable")
);

$model = $this->model();
$model->updateById($field["fieldId"], $data);

// If there were errors, pass them on to the form.
if ($model->errorCount()) $form->errors($model->errors());

// Otherwise, redirect back to the fields page.
else $this->redirect(URL("admin/profiles"));
}

$this->data("form", $form);
$this->data("field", $field);
$this->render($this->plugin()->view("admin/editField"));
}


public function action_create()
{
// Set up the form.
$form = ETFactory::make("form");
$form->action = URL("admin/profiles/create");

// Was the cancel button pressed?
if ($form->isPostBack("cancel")) $this->redirect(URL("admin/profiles"));

// Was the save button pressed?
if ($form->validPostBack("save")) {

$model = $this->model();

$data = array(
"name" => $form->getValue("name"),
"description" => $form->getValue("description"),
"type" => $form->getValue("type"),
"options" => $form->getValue("options"),
"showOnPosts" => (bool)$form->getValue("showOnPosts"),
"hideFromGuests" => (bool)$form->getValue("hideFromGuests"),
"searchable" => (bool)$form->getValue("searchable"),
"position" => $model->count()
);

$model->create($data);

// If there were errors, pass them on to the form.
if ($model->errorCount()) $form->errors($model->errors());

// Otherwise, redirect back to the fields page.
else $this->redirect(URL("admin/profiles"));
}

$this->data("form", $form);
$this->data("field", null);
$this->render($this->plugin()->view("admin/editField"));
}


public function action_delete($fieldId = "")
{
if (!$this->validateToken()) return;

// Get this field's details. If it doesn't exist, show an error.
if (!($field = $this->model()->getById((int)$fieldId))) {
$this->render404();
return;
}

$this->model()->deleteById($field["fieldId"]);

$this->redirect(URL("admin/profiles"));
}

public function action_reorder()
{
if (!$this->validateToken()) return;

$ids = (array)R("ids");

for ($i = 0; $i < count($ids); $i++) {
$this->model()->updateById($ids[$i], array("position" => $i));
}
}

}
31 changes: 31 additions & 0 deletions addons/plugins/Profiles/README.md
@@ -0,0 +1,31 @@
# Profiles Plugin

Allows custom fields to be added to user profiles.

## Installation

[Download](https://github.com/esotalk/Profiles/archive/master.zip) or clone the Profiles plugin repo into your esoTalk plugin directory:

cd ESOTALK_DIR/addons/plugins/
git clone git@github.com:esotalk/Profiles.git Profiles

Navigate to the the admin/plugins page and activate the Profiles plugin.

## Translation

Create `definitions.Profiles.php` in your language pack with the following definitions:

$definitions["About"] = "About";
$definitions["Create Field"] = "Create Field";
$definitions["Edit Field"] = "Edit Field";
$definitions["Field description"] = "Field description";
$definitions["Field name"] = "Field name";
$definitions["Hide field from guests"] = "Hide field from guests";
$definitions["Input type"] = "Input type";
$definitions["Location"] = "Location";
$definitions["Manage Profile Fields"] = "Manage Profile Fields";
$definitions["Options"] = "Options";
$definitions["Privacy"] = "Privacy";
$definitions["Show field on posts"] = "Show field on posts";
$definitions["Write something about yourself."] = "Write something about yourself.";

Binary file added addons/plugins/Profiles/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.

0 comments on commit a5e03b9

Please sign in to comment.