Example #1
0
 /**
  * Returns form body HTML
  * @return string
  */
 public function viewBody()
 {
     // Get sticky values
     $sticky_values = hypePrototyper()->prototype->getStickyValues($this->action);
     hypePrototyper()->prototype->clearStickyValues($this->action);
     // Get validation errors and messages
     $validation_status = hypePrototyper()->prototype->getValidationStatus($this->action);
     hypePrototyper()->prototype->clearValidationStatus($this->action);
     // Prepare fields
     $i = 0;
     foreach ($this->fields as $field) {
         if (!$field instanceof Field) {
             continue;
         }
         if ($field->getInputView() === false) {
             continue;
         }
         $shortname = $field->getShortname();
         if (isset($sticky_values[$shortname])) {
             $field->setStickyValue($sticky_values[$shortname]);
         }
         if (isset($validation_status[$shortname])) {
             $field->setValidation($validation_status[$shortname]['status'], $validation_status[$shortname]['messages']);
         }
         $output .= $field->viewInput(array('index' => $i, 'entity' => $this->entity));
         $i++;
     }
     $submit = elgg_view('prototyper/input/submit', array('entity' => $this->entity, 'action' => $this->action));
     $output .= elgg_format_element('div', array('class' => 'elgg-foot'), $submit);
     return $output;
 }
/**
 * Init
 * @return void
 */
function prototyper_validators_init()
{
    elgg_extend_view('prototyper/elements/help', 'prototyper/elements/validation');
    elgg_extend_view('prototyper/input/before', 'prototyper/elements/js_validation');
    elgg_register_plugin_hook_handler('validate:type', 'prototyper', 'prototyper_validate_type');
    hypePrototyper()->config->registerValidationRule('type', array('string', 'alnum', 'alpha', 'int', 'numeric', 'date', 'url', 'email', 'guid', 'image'));
    elgg_register_plugin_hook_handler('validate:min', 'prototyper', 'prototyper_validate_min');
    hypePrototyper()->config->registerValidationRule('min');
    elgg_register_plugin_hook_handler('validate:max', 'prototyper', 'prototyper_validate_max');
    hypePrototyper()->config->registerValidationRule('max');
    elgg_register_plugin_hook_handler('validate:minlength', 'prototyper', 'prototyper_validate_minlength');
    hypePrototyper()->config->registerValidationRule('minlength');
    elgg_register_plugin_hook_handler('validate:maxlength', 'prototyper', 'prototyper_validate_maxlength');
    hypePrototyper()->config->registerValidationRule('maxlength');
    elgg_register_plugin_hook_handler('validate:contains', 'prototyper', 'prototyper_validate_contains');
    hypePrototyper()->config->registerValidationRule('contains');
    elgg_register_plugin_hook_handler('validate:regex', 'prototyper', 'prototyper_validate_regex');
    hypePrototyper()->config->registerValidationRule('regex');
    if (\hypeJunction\Integration::isElggVersionBelow('1.9.0')) {
        elgg_register_js('parsley', '/mod/hypePrototyperValidators/vendors/parsley/parsley.min.js', 'footer');
        elgg_register_simplecache_view('js/framework/legacy/prototyper_validation');
        elgg_register_js('prototyper_validation', elgg_get_simplecache_url('js', 'framework/legacy/prototyper_validation'), 'footer');
    } else {
        elgg_define_js('parsley', array('src' => '/mod/hypePrototyperValidators/vendors/parsley/parsley.min.js', 'deps' => array('jquery')));
    }
    elgg_register_plugin_hook_handler('input_vars', 'prototyper', 'prototyper_filter_input_view_vars');
}
/**
 * Populates the profile fields config with prototyped values
 *
 * @param string $hook   "prototype"
 * @param string $type   "profile/edit"
 * @param array  $return Fields
 * @param array  $params Hook params
 * @return array
 */
function prototyper_profile_get_config_fields($hook, $type, $return, $params)
{
    $user = hypePrototyper()->entityFactory->build(['type' => 'user']);
    $fields = hypePrototyper()->prototype->fields($user, 'profile/edit');
    foreach ($fields as $field) {
        /* @var $field \hypeJunction\Prototyper\Elements\Field */
        if ($field->getDataType() !== 'metadata') {
            // only add metadata fields
            continue;
        }
        $shortname = $field->getShortname();
        if (!array_key_exists($shortname, $return)) {
            $return[$shortname] = $field->getType();
        }
    }
    return $return;
}
/**
 * Populates the profile fields config with prototyped values
 *
 * @param string $hook   "prototype"
 * @param string $type   "groups/edit"
 * @param array  $return Fields
 * @param array  $params Hook params
 * @return array
 */
function prototyper_group_get_config_fields($hook, $type, $return, $params)
{
    $subtype = elgg_extract('subtype', $params);
    $group = hypePrototyper()->entityFactory->build(['type' => 'group', 'subtype' => $subtype ?: ELGG_ENTITIES_ANY_VALUE]);
    $fields = hypePrototyper()->prototype->fields($group, 'groups/edit');
    foreach ($fields as $field) {
        /* @var $field \hypeJunction\Prototyper\Elements\Field */
        if ($field->getDataType() !== 'metadata') {
            // only add metadata fields
            continue;
        }
        $shortname = $field->getShortname();
        if (!array_key_exists($shortname, $return)) {
            $return[$shortname] = $field->getType();
        }
    }
    return $return;
}
								<div class="prototyper-col-5">
									<label><?php 
echo elgg_echo('prototyper:ui:validation:rule');
?>
</label>
								</div>
								<div class="prototyper-col-5">
									<label><?php 
echo elgg_echo('prototyper:ui:validation:expectation');
?>
</label>
								</div>
							</div>
							<div class="prototyper-ui-options-list">
								<?php 
$validation_rule_defs = hypePrototyper()->config->getValidationRules();
$validation_rule_defs_options = array('' => '');
foreach ($validation_rule_defs as $rule => $rule_opts) {
    $validation_rule_defs_options[$rule] = elgg_echo("prototyper:ui:validation:rule:{$rule}");
}
$validation_rules = $field->getValidationRules();
if (empty($validation_rules)) {
    $validation_rules = array('' => '');
}
foreach ($validation_rules as $rule => $expectation) {
    ?>
									<div class="prototyper-row prototyper-ui-validation-item">
										<div class="prototyper-col-2 no-padding">
											<?php 
    echo elgg_view('output/url', array('class' => 'prototyper-ui-validation-move', 'text' => elgg_view_icon('prototyper-ui-move'), 'href' => '#'));
    echo elgg_view('output/url', array('class' => 'prototyper-ui-validation-add', 'text' => elgg_view_icon('prototyper-ui-add'), 'href' => '#'));
<?php

$entity = elgg_extract('entity', $vars);
echo hypePrototyper()->profile->with($entity, 'groups/edit')->filter(function (hypeJunction\Prototyper\Elements\Field $field) {
    return !in_array($field->getShortname(), ['name', 'vis', 'membership', 'content_access_mode', 'tools', 'owner_guid', 'icon']);
})->view();
Example #7
0
<?php

/**
 * Form Prototyper
 *
 * @author Ismayil Khayredinov <*****@*****.**>
 */
require_once __DIR__ . '/autoloader.php';
hypePrototyper()->boot();
<?php

$entity = elgg_extract('entity', $vars);
echo hypePrototyper()->form->with($entity, 'profile/edit')->viewBody();
<?php

$subtype = get_input('subtype', 'default');
$prototype = hypePrototyper()->ui->buildPrototypeFromInput();
if ($prototype && elgg_set_plugin_setting("prototype:{$subtype}", serialize($prototype), 'prototyper_group')) {
    system_message(elgg_echo('groups:prototype:success'));
} else {
    register_error(elgg_echo('groups:prototype:error'));
}
forward(REFERER);
<?php

$guid = get_input('guid');
$user = get_entity($guid);
if (!$user || !$user instanceof ElggUser || !$user->canEdit()) {
    register_error(elgg_echo('profile:noaccess'));
    forward(REFERER);
}
try {
    $action = hypePrototyper()->action->with($user, 'profile/edit');
    if ($action->validate()) {
        $result = $action->update();
    }
} catch (\hypeJunction\Exceptions\ActionValidationException $ex) {
    register_error(elgg_echo('prototyper:validate:error'));
    forward(REFERER);
} catch (\IOException $ex) {
    register_error(elgg_echo('prototyper:io:error', [$ex->getMessage()]));
    forward(REFERER);
} catch (\Exception $ex) {
    register_error(elgg_echo('prototyper:handle:error', [$ex->getMessage()]));
    forward(REFERER);
}
if ($result) {
    if (elgg_is_xhr()) {
        echo $action->result->output;
    }
    // Notify of profile update
    elgg_trigger_event('profileupdate', $user->type, $user);
    system_message(elgg_echo("profile:saved"));
    forward($user->getURL());
if (!$group instanceof ElggGroup && elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) {
    register_error(elgg_echo("groups:cantcreate"));
    forward(REFERER);
}
if (!$group instanceof ElggGroup) {
    $subtype = get_input('subtype') ?: ELGG_ENTITIES_ANY_VALUE;
    $container_guid = get_input('container_guid') ?: elgg_get_logged_in_user_guid();
    $group = hypePrototyper()->entityFactory->build(['type' => 'group', 'subtype' => $subtype, 'access_id' => ACCESS_PUBLIC, 'container_guid' => $container_guid]);
}
if (!$group->canEdit()) {
    register_error(elgg_echo("groups:cantedit"));
    forward(REFERER);
}
$is_new_group = empty($group->guid);
try {
    $action = hypePrototyper()->action->with($group, 'groups/edit');
    if ($action->validate()) {
        $group = $action->update();
    }
} catch (\hypeJunction\Exceptions\ActionValidationException $ex) {
    register_error(elgg_echo('prototyper:validate:error'));
    forward(REFERER);
} catch (\IOException $ex) {
    register_error(elgg_echo('prototyper:io:error', [$ex->getMessage()]));
    forward(REFERER);
} catch (\Exception $ex) {
    register_error(elgg_echo('prototyper:handle:error', [$ex->getMessage()]));
    forward(REFERER);
}
if ($group) {
    if (elgg_is_xhr()) {
 /**
  * Updates entity information with user input values
  * @return \ElggEntity|false
  */
 public function update()
 {
     hypePrototyper()->prototype->saveStickyValues($this->action);
     // first handle attributes
     foreach ($this->fields as $field) {
         if ($field->getDataType() == 'attribute') {
             $this->entity = $field->handle($this->entity);
         }
     }
     if (!$this->entity->save()) {
         return false;
     }
     foreach ($this->fields as $field) {
         if ($field->getDataType() !== 'attribute') {
             $this->entity = $field->handle($this->entity);
         }
     }
     if (!$this->entity->save()) {
         return false;
     }
     hypePrototyper()->prototype->clearStickyValues($this->action);
     return $this->entity;
 }
Example #13
0
 /**
  * Init callback
  */
 public function init()
 {
     elgg_extend_view('css/elgg', 'css/framework/prototyper/stylesheet');
     elgg_extend_view('css/admin', 'css/framework/prototyper/stylesheet');
     elgg_register_css('jquery.cropper', '/mod/hypePrototyper/vendors/jquery.cropper/cropper.min.css');
     elgg_extend_view('prototyper/input/before', 'prototyper/elements/js');
     if (\hypeJunction\Integration::isElggVersionBelow('1.9.0')) {
         // Prototyper interface
         elgg_register_simplecache_view('js/framework/legacy/prototyper');
         elgg_register_js('prototyper', elgg_get_simplecache_url('js', 'framework/legacy/prototyper'), 'footer');
         elgg_register_js('jquery.cropper', '/mod/hypePrototyper/vendors/jquery.cropper/cropper.min.js', 'footer');
         elgg_register_simplecache_view('js/framework/legacy/prototyper_cropper');
         elgg_register_js('prototyper_cropper', elgg_get_simplecache_url('js', 'framework/legacy/prototyper_cropper'), 'footer');
     } else {
         elgg_define_js('cropper', array('src' => '/mod/hypePrototyper/vendors/jquery.cropper/cropper.min.js', 'deps' => array('jquery')));
     }
     elgg_extend_view('input/file', 'prototyper/ui/cropper');
     hypePrototyper()->config->registerType('title', Elements\AttributeField::CLASSNAME, array('shortname' => 'title', 'input_view' => 'input/text', 'output_view' => 'output/text', 'value_type' => 'text', 'show_access' => false, 'multiple' => false, 'required' => true, 'ui_sections' => array('multiple' => false, 'access' => false)));
     hypePrototyper()->config->registerType('name', Elements\AttributeField::CLASSNAME, array('shortname' => 'name', 'input_view' => 'input/text', 'output_view' => 'output/text', 'value_type' => 'text', 'show_access' => false, 'multiple' => false, 'required' => true, 'ui_sections' => array('multiple' => false, 'access' => false)));
     hypePrototyper()->config->registerType('description', Elements\AttributeField::CLASSNAME, array('shortname' => 'description', 'input_view' => 'input/longtext', 'output_view' => 'output/longtext', 'value_type' => 'text', 'show_access' => false, 'multiple' => false, 'ui_sections' => array('multiple' => false, 'access' => false)));
     hypePrototyper()->config->registerType('access', Elements\AttributeField::CLASSNAME, array('shortname' => 'access_id', 'value' => get_default_access(), 'input_view' => 'input/access', 'output_view' => 'output/access', 'value_type' => 'int', 'show_access' => false, 'multiple' => false, 'required' => true, 'ui_sections' => array('multiple' => false, 'access' => false)));
     hypePrototyper()->config->registerType('text', Elements\MetadataField::CLASSNAME);
     hypePrototyper()->config->registerType('text', Elements\AnnotationField::CLASSNAME);
     hypePrototyper()->config->registerType('plaintext', Elements\MetadataField::CLASSNAME, array('value_type' => 'text'));
     hypePrototyper()->config->registerType('longtext', Elements\MetadataField::CLASSNAME, array('value_type' => 'text'));
     hypePrototyper()->config->registerType('hidden', Elements\MetadataField::CLASSNAME, array('multiple' => false, 'required' => false, 'show_access' => false, 'label' => false, 'help' => false, 'ui_sections' => array('required' => false, 'access' => false, 'multiple' => false, 'label' => false, 'help' => false)));
     hypePrototyper()->config->registerType('select', Elements\MetadataField::CLASSNAME, array('ui_sections' => array('optionsvalues' => true)));
     hypePrototyper()->config->registerType('access', Elements\MetadataField::CLASSNAME, array('ui_sections' => array('optionsvalues' => false)));
     hypePrototyper()->config->registerType('checkboxes', Elements\MetadataField::CLASSNAME, array('ui_sections' => array('multiple' => false, 'optionsvalues' => true)));
     hypePrototyper()->config->registerType('radio', Elements\MetadataField::CLASSNAME, array('ui_sections' => array('multiple' => false, 'optionsvalues' => true)));
     hypePrototyper()->config->registerType('tags', Elements\MetadataField::CLASSNAME, array('ui_sections' => array('multiple' => false)));
     hypePrototyper()->config->registerType('date', Elements\MetadataField::CLASSNAME, array('timestamp' => false));
     hypePrototyper()->config->registerType('time', Elements\MetadataField::CLASSNAME, array('input_view' => 'input/prototyper/time', 'format' => 'g:ia', 'interval' => 900));
     hypePrototyper()->config->registerType('email', Elements\MetadataField::CLASSNAME);
     hypePrototyper()->config->registerType('url', Elements\MetadataField::CLASSNAME);
     hypePrototyper()->config->registerType('stars', Elements\MetadataField::CLASSNAME, array('value_type' => 'number', 'ui_sections' => array('validation' => false)));
     hypePrototyper()->config->registerType('stars', Elements\AnnotationField::CLASSNAME, array('value_type' => 'number', 'ui_sections' => array('validation' => false)));
     hypePrototyper()->config->registerType('userpicker', Elements\RelationshipField::CLASSNAME, array('value_type' => 'guid', 'inverse_relationship' => false, 'bilateral' => false, 'multiple' => false, 'show_access' => false, 'ui_sections' => array('access' => false, 'multiple' => false, 'relationship' => true)));
     hypePrototyper()->config->registerType('friendspicker', Elements\RelationshipField::CLASSNAME, array('value_type' => 'guid', 'inverse_relationship' => false, 'bilateral' => false, 'multiple' => false, 'show_access' => false, 'ui_sections' => array('access' => false, 'multiple' => false, 'relationship' => true)));
     if (elgg_is_active_plugin('hypeCategories')) {
         hypePrototyper()->config->registerType('category', Elements\CategoryField::CLASSNAME, array('value_type' => 'guid', 'inverse_relationship' => false, 'bilateral' => false, 'multiple' => true, 'show_access' => false, 'ui_sections' => array('access' => false, 'multiple' => true, 'relationship' => false)));
     }
     hypePrototyper()->config->registerType('icon', Elements\IconField::CLASSNAME, array('accept' => 'image/*', 'value_type' => 'image', 'multiple' => false, 'show_access' => false, 'input_view' => 'input/file', 'output_view' => 'icon/default', 'ui_sections' => array('value' => false, 'access' => false, 'multiple' => false)));
     hypePrototyper()->config->registerType('upload', Elements\UploadField::CLASSNAME, array('multiple' => false, 'show_access' => false, 'input_view' => 'input/file', 'ui_sections' => array('value' => true, 'access' => false, 'multiple' => false, 'validation' => true)));
     hypePrototyper()->config->registerType('image_upload', Elements\ImageUploadField::CLASSNAME, array('multiple' => false, 'accept' => 'image/*', 'value_type' => 'image', 'show_access' => false, 'input_view' => 'input/file', 'validation_rules' => array('type' => 'image'), 'ui_sections' => array('value' => true, 'access' => false, 'multiple' => false, 'validation' => true)));
 }
<?php

/**
 * Group edit form
 *
 * @package ElggGroups
 */
elgg_require_js('elgg/groups/edit');
$entity = elgg_extract('entity', $vars);
$subtype = elgg_extract('subtype', $vars);
$container_guid = elgg_extract('container_guid', $vars) ?: ELGG_ENTITIES_ANY_VALUE;
if (!$subtype) {
    $subtype = 'default';
}
if (!$entity) {
    $entity = hypePrototyper()->entityFactory->build(['type' => 'group', 'subtype' => $subtype == 'default' ? ELGG_ENTITIES_ANY_VALUE : $subtype, 'container_guid' => $container_guid, 'access_id' => get_default_access(), 'membership' => ACCESS_PUBLIC]);
    $entity->setContentAccessMode(ElggGroup::CONTENT_ACCESS_MODE_UNRESTRICTED);
}
// context needed for input/access view
elgg_push_context("group-edit");
echo hypePrototyper()->form->with($entity, 'groups/edit')->view(['validate' => true]);
elgg_pop_context();
<?php

/**
 * Elgg user display (details)
 * @uses $vars['entity'] The user entity
 */
$user = elgg_get_page_owner_entity();
$profile_fields = elgg_get_config('profile_fields');
echo '<div id="profile-details" class="elgg-body pll">';
echo "<span class=\"hidden nickname p-nickname\">{$user->username}</span>";
echo "<h2 class=\"p-name fn\">{$user->name}</h2>";
// the controller doesn't allow non-admins to view banned users' profiles
if ($user->isBanned()) {
    $title = elgg_echo('banned');
    $reason = $user->ban_reason === 'banned' ? '' : $user->ban_reason;
    echo "<div class='profile-banned-user'><h4 class='mbs'>{$title}</h4>{$reason}</div>";
}
echo elgg_view("profile/status", ["entity" => $user]);
echo hypePrototyper()->profile->with($user, 'profile/edit')->filter(function (hypeJunction\Prototyper\Elements\Field $field) {
    return !in_array($field->getShortname(), ['username', 'name', 'ban_reason', 'description']);
})->view();
if ($user->description) {
    echo "<p class='profile-aboutme-title'><b>" . elgg_echo("profile:aboutme") . "</b></p>";
    echo "<div class='profile-aboutme-contents'>";
    echo elgg_view('output/longtext', ['value' => $user->description, 'class' => 'mtn']);
    echo "</div>";
}
echo '</div>';
Example #16
0
?>
<div class="prototyper-ui-dashboard prototyper-row">
	<div class="prototyper-col-3">
		<div class="prototyper-ui-attribute-fields">
			<?php 
echo elgg_view('forms/prototyper/attributes', array('fields' => $fields));
?>
		</div>
		<div class="prototyper-ui-dashboard-source">
			<?php 
foreach ($templates as $dt => $dt_options) {
    echo '<h3>' . elgg_echo("prototyper:ui:{$dt}") . '</h3>';
    foreach ($dt_options as $it => $it_options) {
        echo elgg_format_element('h4', array('class' => 'prototyper-ui-add', 'data-dt' => $dt, 'data-it' => $it), elgg_echo("prototyper:ui:{$it}"));
        $shortname = "prototyper_{$dt_}{$it}";
        $field = hypePrototyper()->fieldFactory->build(array('shortname' => $shortname, 'type' => $it, 'data_type' => $dt));
        if (!$field instanceof \hypeJunction\Prototyper\Elements\Field) {
            continue;
        }
        echo elgg_format_element('div', array('class' => 'prototyper-ui-template', 'data-dt' => $dt, 'data-it' => $it), elgg_view('forms/prototyper/template', array('field' => $field, 'entity' => $entity)));
    }
}
?>
		</div>
	</div>
	<div class="prototyper-col-9">
		<div class="prototyper-ui-dashboard-target">
			<?php 
foreach ($fields as $field) {
    if (!$field instanceof \hypeJunction\Prototyper\Elements\Field) {
        continue;