예제 #1
0
function uniqueID($str = '', $id = false)
{
    $temp = $str;
    if (!isset($GLOBALS['BROSTA_INTERFRAMEWORK'])) {
        $GLOBALS['BROSTA_INTERFRAMEWORK'] = [];
        $GLOBALS['BROSTA_INTERFRAMEWORK']['BROSTA_UNIQUE_IDS'] = [];
    }
    $crypt = ['A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z'];
    $random = [];
    while (count($crypt)) {
        $element = array_rand($crypt);
        $random[$element] = $crypt[$element];
        unset($crypt[$element]);
    }
    $crypt = array_values($random);
    for ($i = 0; $i < count($crypt); $i++) {
        if (!$id) {
            $id = '';
        }
        $id .= $crypt[$i];
        if (strlen($id) < 3) {
            return uniqueID($str, $id);
        }
        if (in_array($id, $GLOBALS['BROSTA_INTERFRAMEWORK']['BROSTA_UNIQUE_IDS'])) {
            return uniqueID($str, $id);
        }
        $GLOBALS['BROSTA_INTERFRAMEWORK']['BROSTA_UNIQUE_IDS'][] = $id;
        if ($str) {
            $id = $str . '-' . $id;
        }
        return $id;
    }
}
예제 #2
0
 public function __construct($name, $label = null)
 {
     parent::__construct($name, $label);
     $this->type = 'items';
     $this->multiple = false;
     $this->items = array();
     $this->resourceURL = 'fields/' . $this->type . uniqueID();
     $this->validationLength = -1;
     $this->initialized = false;
     $this->toAdd = array();
     // $that = $this;
     // Router::register('GET', 'manager/api/' . $this->resourceURL, function () use ($that) {
     // 	if (($token = User::validateToken()) !== true)
     // 	{
     // 		return $token;
     // 	}
     // 	$that->module->flag = "C";
     // 	$that->init();
     // 	return Response::json($that->items);
     // });
 }
예제 #3
0
 public function __construct($name, $label, $path)
 {
     parent::__construct($name, $label);
     $this->type = "upload";
     $id = uniqueID();
     $this->sessionKey = "manager_" . $this->type . $id;
     $this->updateURL = "fields/" . $this->type . $id;
     $this->limit = 1;
     $this->hasCaption = false;
     $this->path = $path;
     $this->defaultValue = array();
     $this->accepts = array();
     $this->acceptsMask = null;
     $that = $this;
     Router::register("POST", "manager/api/" . $this->updateURL . "/(:segment)/(:num)/(:segment)", function ($action, $id, $flag) use($that) {
         if (($token = User::validateToken()) !== true) {
             return $token;
         }
         $flag = Str::upper($flag);
         $that->module->flag = $flag;
         switch ($action) {
             default:
             case "update":
                 return Response::json($that->upload($flag, $id));
                 break;
             case "sort":
                 return Response::json($that->sort(Request::post("from", -1), Request::post("to", -1)));
                 break;
             case "caption":
                 return Response::json($that->setCaption((int) Request::post("index", -1), Request::post("caption")));
                 break;
             case "delete":
                 return Response::json($that->delete((int) Request::post("index", -1)));
                 break;
         }
         return Response::code(500);
     });
 }
예제 #4
0
 function __construct($label)
 {
     parent::__construct("title" . uniqueID(), $label);
     $this->type = "title";
     $this->validation("textarea");
 }
예제 #5
0
    function checkString($subject, $type = 'quotes', $maxLength = 0) {

        if (@is_array($subject)) {

            foreach ($subject as $k => $v)
                $subject[$k] = checkString($v, $type, $maxLength);
        } else {

            $subject = trim($subject);
            if ($maxLength)
                $subject = mb_substr($subject, 0, $maxLength);

            //if ($type=='quotes') $subject = str_replace("'", "\'", $subject);

            if ($type == 'digits')
                $subject = preg_replace('/[^\\d]+/', '', $subject);
            if ($type == 'numeric')
                $subject = preg_replace('/[^\\d]+/', '', $subject);
            if ($type == 'alpha')
                $subject = preg_replace('/[^a-zA-Z]+/', '', $subject);
            if ($type == 'al-num')
                $subject = preg_replace('/[^\\w]+/', '', $subject);
            if ($type == 'mail')
                $subject = mb_substr(preg_replace('/[^-@_.\\w]+/', '', $subject), 0, 100);
            if ($type == 'phone')
                $subject = mb_substr(preg_replace('/[^-,.()\\w\\s]+/', '', $subject), 0, 100);
            if ($type == 'url')
                $subject = mb_substr(preg_replace('/[^-_:\/\/.:\\w]+/', '', $subject), 0, 100);
            if ($type == 'file')
                $subject = mb_strtolower(mb_substr(preg_replace('/[^-_.\\w]/', '', str_replace(" ", "_", $subject)), 0, 100));
            if ($type == 'id')
                $subject = mb_substr(preg_replace('/[^-_a-zA-Z0-9]+/', '', str_replace(" ", "_", $subject)), 0, 32);

            if ($type == 'file' && $subject == '')
                $subject = uniqueID();
        }

        return $subject;
    }
예제 #6
0
 public function uniqueID($id = '')
 {
     $this->id(uniqueID($id));
     return $this;
 }
예제 #7
0
 public function body($fields)
 {
     if (isset($fields['fields'])) {
         $fields = $fields['fields'];
     }
     $html = new Html();
     if (!empty($fields)) {
         foreach ($fields as $field) {
             $for = uniqueID();
             $forfrom = $for . '-from';
             $forto = $for . '-to';
             $html->tag('div');
             isset($field['error']) && $field['error'] ? $html->class('form-group row has-danger') : $html->class('form-group row');
             $html->tag('label')->for($for)->class('col-xs-2 col-form-label')->text($field['label']);
             isset($field['extra']) && $field['extra'] ? $html->jsData('show', $for) : false;
             $html->tag();
             $html->tag('div')->class('col-xs-6');
             if (isset($field['prefix']) && $field['prefix'] || isset($field['postfix']) && $field['postfix']) {
                 $html->tag('div')->class('input-group');
                 if (isset($field['prefix']) && $field['prefix']) {
                     $html->tag('span')->class('input-group-addon')->text($field['prefix'])->tag();
                 }
             }
             /* START SELECT */
             if ($field['type'] == 'menu') {
                 $html->tag('select')->id($for);
                 isset($field['onredirectvalue']) && $field['onredirectvalue'] ? $html->jsData('onredirectvalue', $field['onredirectvalue'] . '?' . $field['caption']) : false;
                 isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                 isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                 isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                 if (isset($field['top_label']) && $field['top_label']) {
                     $html->tag('option')->value()->text($field['top_label'])->tag();
                 }
                 foreach ($field['options'] as $option) {
                     $html->tag('option');
                     isset($option['value']) ? $html->value($option['value']) : false;
                     isset($option['selected']) && $option['selected'] ? $html->selected() : false;
                     $html->text($option['text']);
                     $html->tag();
                 }
                 $html->tag();
             }
             /* END SELECT */
             /* START MULTISELECT */
             if ($field['type'] == 'multiselect') {
                 $html->tag('select')->id($for);
                 isset($field['caption']) && $field['caption'] ? $html->name($field['caption'] . '[]') : false;
                 isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                 $html->multiple();
                 foreach ($field['options'] as $option) {
                     $html->tag('option');
                     $html->value($option['value']);
                     isset($option['selected']) && $option['selected'] ? $html->selected() : false;
                     $html->text($option['text']);
                     $html->tag();
                 }
                 $html->tag();
             }
             /* END MULTISELECT */
             /* START OPTGROUP */
             if ($field['type'] == 'optgroup') {
                 $html->tag('select')->id($for);
                 isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                 isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                 isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                 $html->append($html->tool('nested')->optgroup($field['options']));
                 $html->tag();
             }
             /* END OPTGROUP */
             /* START TEXTAREA */
             if ($field['type'] == 'textarea') {
                 $html->tag('textarea')->id($for);
                 isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                 isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                 isset($field['rows']) && $field['rows'] ? $html->rows($field['rows']) : $html->rows(5);
                 isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                 $html->text($field['value']);
                 $html->tag();
             }
             /* END TEXTAREA */
             /* START INPUT */
             if ($field['type'] == 'input') {
                 /* START TEXT */
                 if ($field['ctype'] == 'text') {
                     $html->tag('input')->id($for);
                     isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                     isset($field['ctype']) && $field['ctype'] ? $html->type($field['ctype']) : false;
                     isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                     isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                     $html->value($field['value']);
                     $html->tag();
                 }
                 /* END TEXT */
                 /* START EMAIL */
                 if ($field['ctype'] == 'email') {
                     $html->tag('input')->id($for);
                     isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                     isset($field['ctype']) && $field['ctype'] ? $html->type($field['ctype']) : false;
                     isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                     isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                     $html->value($field['value']);
                     $html->tag();
                 }
                 /* END EMAIL */
                 /* START PASSWORD */
                 if ($field['ctype'] == 'password') {
                     $html->tag('input')->id($for);
                     isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                     isset($field['ctype']) && $field['ctype'] ? $html->type($field['ctype']) : false;
                     isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                     isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                     $html->value($field['value']);
                     $html->tag();
                 }
                 /* END PASSWORD */
                 /* START URL */
                 if ($field['ctype'] == 'url') {
                     $html->tag('input')->id($for);
                     isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                     isset($field['ctype']) && $field['ctype'] ? $html->type($field['ctype']) : false;
                     isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                     isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                     $html->value($field['value']);
                     $html->tag();
                 }
                 /* END URL */
                 /* START DATE */
                 if ($field['ctype'] == 'date') {
                     if (isset($field['double']) && $field['double']) {
                         $html->tag('div');
                         isset($field['from']['error']) && $field['from']['error'] ? $html->class('form-group has-error') : $html->class('form-group');
                         $html->style('margin-bottom:8px');
                         $html->tag('label')->for($forfrom)->text($field['from']['label']);
                         isset($field['extra']) && $field['extra'] ? $html->jsData('show', $forfrom) : false;
                         $html->tag();
                         if (isset($field['from']['prefix']) && $field['from']['prefix'] || isset($field['from']['postfix']) && $field['from']['postfix']) {
                             $html->tag('div')->class('input-group');
                             if (isset($field['from']['prefix']) && $field['from']['prefix']) {
                                 $html->tag('span')->class('input-group-addon')->text($field['from']['prefix'])->tag();
                             }
                         }
                         $html->tag('input')->id($forfrom);
                         isset($field['from']['style']) && $field['from']['style'] ? $html->style($field['from']['style']) : false;
                         isset($field['from']['ctype']) && $field['from']['ctype'] ? $html->type($field['from']['ctype']) : false;
                         isset($field['from']['caption']) && $field['from']['caption'] ? $html->name($field['from']['caption']) : false;
                         isset($field['from']['class']) && $field['from']['class'] ? $html->class($field['from']['class']) : false;
                         $html->value($field['from']['value']);
                         $html->tag();
                         isset($field['from']['error']) && $field['from']['error'] ? $html->tag('span')->class('help-block')->text($field['from']['error'])->tag() : false;
                         isset($field['from']['msg_info']) && $field['from']['msg_info'] ? $html->tag('span')->class('help-block')->text($field['from']['msg_info'])->tag() : false;
                         $html->tag();
                         $html->tag('div');
                         isset($field['to']['error']) && $field['to']['error'] ? $html->class('form-group has-error') : $html->class('form-group');
                         $html->style('margin-bottom:8px');
                         $html->tag('label')->for($forto)->text($field['to']['label']);
                         isset($field['extra']) && $field['extra'] ? $html->jsData('show', $field['to']['caption']) : false;
                         $html->tag();
                         if (isset($field['to']['prefix']) && $field['to']['prefix'] || isset($field['to']['postfix']) && $field['to']['postfix']) {
                             $html->tag('div')->class('input-group');
                             if (isset($field['to']['prefix']) && $field['to']['prefix']) {
                                 $html->tag('span')->class('input-group-addon')->text($field['to']['prefix'])->tag();
                             }
                         }
                         $html->tag('input')->id($forto);
                         isset($field['to']['style']) && $field['to']['style'] ? $html->style($field['to']['style']) : false;
                         isset($field['to']['ctype']) && $field['to']['ctype'] ? $html->type($field['to']['ctype']) : false;
                         isset($field['to']['caption']) && $field['to']['caption'] ? $html->name($field['to']['caption']) : false;
                         isset($field['to']['class']) && $field['to']['class'] ? $html->class($field['to']['class']) : false;
                         $html->value($field['to']['value']);
                         $html->tag();
                         isset($field['to']['error']) && $field['to']['error'] ? $html->tag('span')->class('help-block')->text($field['to']['error'])->tag() : false;
                         isset($field['to']['msg_info']) && $field['to']['msg_info'] ? $html->tag('span')->class('help-block')->text($field['to']['msg_info'])->tag() : false;
                         $html->tag();
                     } else {
                         $html->tag('input')->id($for);
                         isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                         isset($field['ctype']) && $field['ctype'] ? $html->type($field['ctype']) : false;
                         isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                         isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                         $html->value($field['value']);
                         $html->tag();
                     }
                 }
                 /* END DATE */
                 /* START COLOR */
                 if ($field['ctype'] == 'color') {
                     $html->tag('input')->id($for);
                     isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                     isset($field['ctype']) && $field['ctype'] ? $html->type($field['ctype']) : false;
                     isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                     isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                     $html->value($field['value']);
                     $html->tag();
                 }
                 /* END COLOR */
                 /* START CHECKBOX */
                 if ($field['ctype'] == 'checkbox') {
                     $html->tag('input')->id($for);
                     isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                     isset($field['ctype']) && $field['ctype'] ? $html->type($field['ctype']) : false;
                     isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                     isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                     isset($field['checked']) && $field['checked'] ? $html->checked() : false;
                     $html->tag();
                 }
                 /* END COLOR */
                 /* START CHECKBOX */
                 if ($field['ctype'] == 'radio') {
                     $html->tag('input')->id($for);
                     isset($field['style']) && $field['style'] ? $html->style($field['style']) : false;
                     isset($field['ctype']) && $field['ctype'] ? $html->type($field['ctype']) : false;
                     isset($field['caption']) && $field['caption'] ? $html->name($field['caption']) : false;
                     isset($field['class']) && $field['class'] ? $html->class($field['class']) : false;
                     isset($field['checked']) && $field['checked'] ? $html->checked() : false;
                     $html->tag();
                 }
                 /* END COLOR */
             }
             /* END INPUT */
             /* END TYPES */
             if (isset($field['prefix']) && $field['prefix'] || isset($field['postfix']) && $field['postfix']) {
                 if (isset($field['postfix']) && $field['postfix']) {
                     $html->tag('span')->class('input-group-addon')->text($field['postfix'])->tag();
                 }
                 $html->tag();
             }
             isset($field['error']) && $field['error'] ? $html->tag('div ')->class('form-control-feedback')->text($field['error'])->tag() : false;
             isset($field['msg_info']) && $field['msg_info'] ? $html->tag('div')->class('form-text text-muted')->text($field['msg_info'])->tag() : false;
             $html->tag();
             $html->tag();
             if (isset($field['extra']) && $field['extra']) {
                 $html->tag('div')->class('display_none')->data('hide', $for)->text($this->body($field['extra']))->tag();
             }
         }
         return $html->give();
     }
     return false;
 }