当前位置: 首页>>代码示例>>PHP>>正文


PHP Upload::getInstance方法代码示例

本文整理汇总了PHP中Upload::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::getInstance方法的具体用法?PHP Upload::getInstance怎么用?PHP Upload::getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Upload的用法示例。


在下文中一共展示了Upload::getInstance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: check

 /**
  * Check the submitted value of the input
  *
  * @param Form $form The form the input is associated with
  *
  * @return boolean true if the uploaded files are correct, else false
  */
 public function check(&$form = null)
 {
     if (empty($this->errorAt)) {
         $this->errorAt = $this->name;
     }
     $basename = preg_replace("/^(\\w+)(\\[.*)?\$/", "\$1", $this->name);
     $upload = Upload::getInstance($basename);
     if ($this->required && !$upload) {
         // No file were uploaded
         $form->error($this->errorAt, Lang::get('form.required-field'));
         return false;
     }
     if ($upload && $this->extensions) {
         foreach ($upload->getFiles() as $file) {
             if (!in_array($file->extension, $this->extensions)) {
                 // One of the uploaded files has no good extension
                 $form && $form->error($this->errorAt, Lang::get('form.invalid-file-extension'));
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:elvyrra,项目名称:hawk,代码行数:30,代码来源:FileInput.php

示例2: addMedia

 /**
  * Add a new media
  */
 public function addMedia()
 {
     $form = $this->addMediaForm();
     if ($form->check()) {
         $uploader = Upload::getInstance('medias');
         $dir = Theme::getSelected()->getMediasDir();
         if (!is_dir($dir)) {
             mkdir($dir, 0755, true);
         }
         foreach ($uploader->getFiles() as $file) {
             $uploader->move($file, Theme::getSelected()->getMediasDir());
         }
         return $form->response(Form::STATUS_SUCCESS);
     }
 }
开发者ID:elvyrra,项目名称:hawk,代码行数:18,代码来源:ThemeController.php

示例3: uploadProfileImage

function uploadProfileImage()
{
    $session = Session::getInstance();
    $user = User::getInstance();
    $storage = Storage::getInstance();
    $upload = Upload::getInstance();
    $res = $upload->writeProfileImage();
    $err = false == $res ? '' : $session->flushError();
    $res = false == $res ? 'false' : $res;
    $res = array('req' => 'profileImageUpload', 'res' => $res);
    return $res;
}
开发者ID:vberzsin,项目名称:2014,代码行数:12,代码来源:index.php

示例4: settings

 /**
  * Display and treat application settings
  */
 public function settings()
 {
     $languages = array_map(function ($language) {
         return $language->label;
     }, Language::getAll('tag'));
     $roleObjects = Role::getListByExample(new DBExample(array('id' => array('$ne' => 0))), 'id');
     $roles = array();
     foreach ($roleObjects as $role) {
         $roles[$role->id] = Lang::get("roles.role-{$role->id}-label");
     }
     $items = MenuItem::getAvailableItems();
     $menuItems = array();
     foreach ($items as $item) {
         if ($item->action && !preg_match('/^(javascript\\:|#)/', $item->action) && (!$item->target || $item->target == 'newtab')) {
             if ($item->label === 'user.username') {
                 $item->label = App::session()->getUser()->username;
             }
             $menuItems[$item->action] = $item->label;
         } else {
             foreach ($item->visibleItems as $subitem) {
                 if ($item->label === 'user.username') {
                     $item->label = App::session()->getUser()->username;
                 }
                 if (!preg_match('/^(javascript\\:|#)/', $subitem->action) && (!$subitem->target || $subitem->target == 'newtab')) {
                     $menuItems[$subitem->action] = $item->label . " > " . $subitem->label;
                 }
             }
         }
     }
     $api = new HawkApi();
     try {
         $updates = $api->getCoreAvailableUpdates();
     } catch (\Hawk\HawkApiException $e) {
         $updates = array();
     }
     $param = array('id' => 'settings-form', 'upload' => true, 'fieldsets' => array('main' => array(new TextInput(array('name' => 'main_sitename', 'required' => true, 'default' => Option::get('main.sitename'), 'label' => Lang::get('admin.settings-sitename-label'))), new SelectInput(array('name' => 'main_language', 'required' => true, 'options' => $languages, 'default' => Option::get('main.language'), 'label' => Lang::get('admin.settings-language-label'))), new SelectInput(array('name' => 'main_timezone', 'required' => true, 'options' => array_combine(\DateTimeZone::listIdentifiers(), \DateTimeZone::listIdentifiers()), 'default' => Option::get('main.timezone'), 'label' => Lang::get('admin.settings-timezone-label'))), new SelectInput(array('name' => 'main_currency', 'required' => true, 'options' => array('EUR' => 'Euro (€)', 'USD' => 'US Dollar ($)'), 'default' => Option::get('main.currency'), 'label' => Lang::get('admin.settings-currency-label'))), new FileInput(array('name' => 'logo', 'label' => Lang::get('admin.settings-logo-label'), 'after' => Option::get('main.logo') ? '<img src="' . Plugin::get('main')->getUserfilesUrl(Option::get('main.logo')) . '" class="settings-logo-preview" />' : '', 'maxSize' => 200000, 'extensions' => array('gif', 'png', 'jpg', 'jpeg'))), new FileInput(array('name' => 'favicon', 'label' => Lang::get('admin.settings-favicon-label'), 'after' => Option::get('main.favicon') ? '<img src="' . Plugin::get('main')->getUserfilesUrl(Option::get('main.favicon')) . '" class="settings-favicon-preview" />' : '', 'maxSize' => 20000, 'extensions' => array('gif', 'png', 'jpg', 'jpeg', 'ico')))), 'referencing' => call_user_func(function () use($languages) {
         $inputs = array();
         foreach ($languages as $tag => $language) {
             $inputs[] = new TextInput(array('name' => 'main_page-title-' . $tag, 'default' => Option::get('main.page-title-' . $tag)));
             $inputs[] = new TextareaInput(array('name' => 'main_page-description-' . $tag, 'default' => Option::get('main.page-description-' . $tag)));
             $inputs[] = new TextInput(array('name' => 'main_page-keywords-' . $tag, 'default' => Option::get('main.page-keywords-' . $tag)));
         }
         return $inputs;
     }), 'home' => array(new RadioInput(array('name' => 'main_home-page-type', 'options' => array('default' => Lang::get('admin.settings-home-page-type-default'), 'custom' => Lang::get('admin.settings-home-page-type-custom'), 'page' => Lang::get('admin.settings-home-page-type-page')), 'default' => Option::get('main.home-page-type') ? Option::get('main.home-page-type') : 'default', 'label' => Lang::get('admin.settings-home-page-type-label'), 'layout' => 'vertical', 'attributes' => array('e-value' => 'homePage.type'))), new WysiwygInput(array('name' => 'main_home-page-html', 'id' => 'home-page-html', 'label' => Lang::get('admin.settings-home-page-html-label'), 'default' => Option::get('main.home-page-html'))), new SelectInput(array('name' => 'main_home-page-item', 'id' => 'home-page-item', 'label' => Lang::get('admin.settings-home-page-item-label'), 'options' => $menuItems, 'value' => Option::get('main.home-page-item'))), new CheckboxInput(array('name' => 'main_open-last-tabs', 'label' => Lang::get('admin.settings-open-last-tabs'), 'default' => Option::get('main.open-last-tabs'), 'dataType' => 'int'))), 'users' => array(new RadioInput(array('name' => 'main_allow-guest', 'options' => array(0 => Lang::get('main.no-txt'), 1 => Lang::get('main.yes-txt')), 'default' => Option::get('main.allow-guest') ? Option::get('main.allow-guest') : 0, 'label' => Lang::get('admin.settings-allow-guest-label'))), new RadioInput(array('name' => 'main_open-register', 'options' => array(0 => Lang::get('admin.settings-open-register-off'), 1 => Lang::get('admin.settings-open-register-on')), 'layout' => 'vertical', 'label' => Lang::get('admin.settings-open-registers-label'), 'default' => Option::get('main.open-register') ? Option::get('main.open-register') : 0, 'attributes' => array('e-value' => 'register.open'))), new CheckboxInput(array('name' => 'main_confirm-register-email', 'label' => Lang::get('admin.settings-confirm-email-label'), 'default' => Option::get('main.confirm-register-email'), 'dataType' => 'int', 'attributes' => array('e-value' => 'register.checkEmail'))), new WysiwygInput(array('name' => 'main_confirm-email-content', 'id' => 'settings-confirm-email-content-input', 'default' => Option::get('main.confirm-email-content'), 'label' => Lang::get('admin.settings-confirm-email-content-label'), 'labelWidth' => 'auto')), new CheckboxInput(array('name' => 'main_confirm-register-terms', 'label' => Lang::get('admin.settings-confirm-terms-label'), 'default' => Option::get('main.confirm-register-terms'), 'dataType' => 'int', 'labelWidth' => 'auto', 'attributes' => array('e-value' => 'register.checkTerms'))), new WysiwygInput(array('name' => 'main_terms', 'id' => 'settings-terms-input', 'label' => Lang::get('admin.settings-terms-label'), 'labelWidth' => 'auto', 'default' => Option::get('main.terms'))), new SelectInput(array('name' => 'roles_default-role', 'label' => Lang::get('admin.settings-default-role-label'), 'options' => $roles, 'default' => Option::get('roles.default-role')))), 'email' => array(new EmailInput(array('name' => 'main_mailer-from', 'default' => Option::get('main.mailer-from') ? Option::get('main.mailer-from') : App::session()->getUser()->email, 'label' => Lang::get('admin.settings-mailer-from-label'))), new TextInput(array('name' => 'main_mailer-from-name', 'default' => Option::get('main.mailer-from-name') ? Option::get('main.mailer-from-name') : App::session()->getUser()->getDisplayName(), 'label' => Lang::get('admin.settings-mailer-from-name-label'))), new SelectInput(array('name' => 'main_mailer-type', 'default' => Option::get('main.mailer-type'), 'options' => array('mail' => Lang::get('admin.settings-mailer-type-mail-value'), 'smtp' => Lang::get('admin.settings-mailer-type-smtp-value'), 'pop3' => Lang::get('admin.settings-mailer-type-pop3-value')), 'label' => Lang::get('admin.settings-mailer-type-label'), 'attributes' => array('e-value' => 'mail.type'))), new TextInput(array('name' => 'main_mailer-host', 'default' => Option::get('main.mailer-host'), 'label' => Lang::get('admin.settings-mailer-host-label'))), new IntegerInput(array('name' => 'main_mailer-port', 'default' => Option::get('main.mailer-port'), 'label' => Lang::get('admin.settings-mailer-port-label'), 'size' => 4)), new TextInput(array('name' => 'main_mailer-username', 'default' => Option::get('main.mailer-username'), 'label' => Lang::get('admin.settings-mailer-username-label'))), new PasswordInput(array('name' => 'main_mailer-password', 'encrypt' => 'Crypto::aes256Encode', 'decrypt' => 'Crypto::aes256Decode', 'default' => Option::get('main.mailer-password'), 'label' => Lang::get('admin.settings-mailer-password-label'))), new SelectInput(array('name' => 'main_smtp-secured', 'options' => array('' => Lang::get('main.no-txt'), 'ssl' => 'SSL', 'tsl' => 'TSL'), 'label' => Lang::get('admin.settings-smtp-secured-label')))), '_submits' => array(empty($updates) ? new HtmlInput(array('value' => '<span class="btn btn-success">' . Lang::get('admin.hawk-version-up-to-date', array('version' => HAWK_VERSION)) . '</span>')) : new ButtonInput(array('name' => 'update-hawk', 'value' => Lang::get('admin.update-page-update-hawk-btn', array('version' => end($updates)['version'])), 'icon' => 'refresh', 'id' => 'update-hawk-btn', 'attributes' => array('e-click' => 'function(){ updateHawk("' . end($updates)['version'] . '"); }'), 'class' => 'btn-warning')), new SubmitInput(array('name' => 'save', 'value' => Lang::get('main.valid-button'), 'class' => 'pull-right')))));
     $form = new Form($param);
     if (!$form->submitted()) {
         // Display the form
         $this->addCss(Plugin::current()->getCssUrl('settings.less'));
         $page = View::make(Plugin::current()->getView('settings.tpl'), array('form' => $form, 'languages' => $languages));
         $this->addKeysToJavaScript('admin.update-page-confirm-update-hawk');
         $this->addJavaScript(Plugin::current()->getJsUrl('settings.js'));
         return NoSidebarTab::make(array('icon' => 'cogs', 'title' => Lang::get('admin.settings-page-name'), 'description' => Lang::get('admin.settings-page-description'), 'page' => $page));
     } else {
         // treat the form
         try {
             if ($form->check()) {
                 // register scalar values
                 foreach ($form->inputs as $name => $field) {
                     if (!$field instanceof \Hawk\FileInput && !$field instanceof \Hawk\ButtonInput && !$field instanceof \Hawk\HtmlInput) {
                         $value = $field->dbvalue();
                         if ($value === null) {
                             $value = '0';
                         }
                         $optionName = str_replace('_', '.', $name);
                         App::logger()->error("Option name =" . $optionName . 'X');
                         App::logger()->error("basename=" . $value . 'X');
                         Option::set($optionName, $value);
                     } elseif ($field instanceof \Hawk\FileInput) {
                         $upload = Upload::getInstance($name);
                         if ($upload) {
                             try {
                                 $file = $upload->getFile();
                                 $dir = Plugin::get('main')->getPublicUserfilesDir();
                                 if (!is_dir($dir)) {
                                     mkdir($dir, 0755);
                                 }
                                 if ($name == 'favicon') {
                                     $basename = uniqid() . '.ico';
                                     $generator = new \PHPICO($file->tmpFile, array(array(16, 16), array(32, 32), array(48, 48), array(64, 64)));
                                     $generator->save_ico($dir . $basename);
                                 } else {
                                     $basename = uniqid() . '.' . $file->extension;
                                     $upload->move($file, $dir, $basename);
                                 }
                                 // remove the old image
                                 @unlink($dir . Option::get("main.{$name}"));
                                 App::logger()->error("Option name = " . $name);
                                 App::logger()->error("main.{$name}");
                                 App::logger()->error("basename=" . $basename);
                                 Option::set("main.{$name}", $basename);
                             } catch (ImageException $e) {
                                 $form->error($name, Lang::get('form.image-format'));
                                 throw $e;
                             }
                         }
                     }
                 }
//.........这里部分代码省略.........
开发者ID:elvyrra,项目名称:hawk,代码行数:101,代码来源:AdminController.php

示例5: frameResponse

 public function frameResponse(\FrameResponseObject $frameResponseObject)
 {
     require_once PATH_LIB . "format_handling.inc.php";
     $env = \steam_factory::get_object($GLOBALS["STEAM"]->get_id(), $this->id);
     if (!($env && $env instanceof \steam_container)) {
         throw new Exception("Environment unknown.");
     }
     $koala_env = \koala_object::get_koala_object($env);
     $backlink = empty($_POST["values"]["backlink"]) ? $_SERVER["HTTP_REFERER"] : $_POST["values"]["backlink"];
     $max_file_size = parse_filesize(ini_get('upload_max_filesize'));
     $max_post_size = parse_filesize(ini_get('post_max_size'));
     if ($max_post_size > 0 && $max_post_size < $max_file_size) {
         $max_file_size = $max_post_size;
     }
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $values = isset($_POST["values"]) ? $_POST["values"] : array();
         $problems = "";
         $hints = "";
         if (empty($_FILES) || !empty($_FILES["material"]["error"]) && $_FILES["material"]["error"] > 0) {
             if (!empty($_FILES) && empty($_FILES["material"]["name"])) {
                 $problems = gettext("No file chosen.") . " ";
                 $hints = gettext("Please choose a local file to upload.") . " ";
             } else {
                 $problems = gettext("Could not upload document.") . " ";
                 $hints = str_replace(array("%SIZE", "%TIME"), array(readable_filesize($max_file_size), (string) ini_get('max_execution_time')), gettext("Maybe your document exceeded the allowed file size (max. %SIZE) or the upload might have taken too long (max. %TIME seconds).")) . " ";
             }
         }
         if (empty($problems)) {
             $content = file_get_contents($_FILES["material"]["tmp_name"]);
             /*
             								ob_start();
             								readfile( $_FILES["material"]["tmp_name"] );
             								$content = ob_get_contents();
             								ob_end_clean();
             */
             if (defined("LOG_DEBUGLOG")) {
                 $time1 = microtime(TRUE);
                 \logging::write_log(LOG_DEBUGLOG, "upload" . " \t" . $GLOBALS["STEAM"]->get_login_user_name() . " \t" . $_FILES["material"]["name"] . " \t" . filesize($_FILES["material"]["tmp_name"]) . " Bytes \t... ");
             }
             $filename = str_replace(array("\\", "'"), array("", ""), $_FILES["material"]["name"]);
             $new_material = \steam_factory::create_document($GLOBALS["STEAM"]->get_id(), $filename, $content, $_FILES["material"]["type"], FALSE);
             if (defined("LOG_DEBUGLOG")) {
                 \logging::append_log(LOG_DEBUGLOG, " \t" . round((microtime(TRUE) - $time1) * 1000) . " ms");
             }
             //  Disabled for Testing issues
             // upload($new_material->get_content_id(), $content);
             if (isset($values["dsc"])) {
                 $new_material->set_attribute("OBJ_DESC", $values["dsc"]);
             }
             $new_material->move($env);
             $_SESSION["confirmation"] = str_replace("%DOCUMENT", h($filename), gettext("'%DOCUMENT' has been uploaded."));
             header("Location: " . $backlink);
             exit;
         } else {
             $frameResponseObject->setTitle(gettext("Upload document"));
             $frameResponseObject->setProblemDescription($problems);
             $frameResponseObject->setProblemSolution($hints);
             $frameResponseObject->addWidget(new \Widgets\Blank());
             return $frameResponseObject;
         }
     }
     $content = \Upload::getInstance()->loadTemplate("upload.template.html");
     $content->setVariable("LABEL_UPLOAD", gettext("Upload"));
     $content->setVariable("LABEL_FILE", gettext("Local file"));
     $content->setVariable("LABEL_DSC", gettext("Description"));
     $content->setVariable("BACKLINK", "<a href=\"{$backlink}\">" . gettext("back") . "</a>");
     $content->setVariable("BACK_LINK", $backlink);
     $content->setVariable("FORM_ACTION", PATH_URL . "upload/to/" . $this->id);
     if ($max_file_size > 0) {
         $content->setVariable("MAX_FILE_SIZE_INPUT", "<input type='hidden' name='MAX_FILE_SIZE' value='" . (string) $max_file_size . "'/>");
         $content->setVariable("MAX_FILE_SIZE_INFO", "<br />" . str_replace("%SIZE", readable_filesize($max_file_size), gettext("The maximum allowed file size is %SIZE.")));
     }
     $link_path = $koala_env->get_link_path();
     if (!is_array($link_path)) {
         $link_path = array();
     }
     $link_path[] = array("name" => gettext("Upload document"));
     $rawHtml = new \Widgets\RawHtml();
     $rawHtml->setHtml($content->get());
     $frameResponseObject->setTitle(gettext("Upload document"));
     $frameResponseObject->setHeadline($link_path);
     $frameResponseObject->addWidget($rawHtml);
     return $frameResponseObject;
 }
开发者ID:rolwi,项目名称:koala,代码行数:84,代码来源:To.class.php

示例6: __construct

 public function __construct()
 {
     @unlink('/tmp/cookie');
     $this->upload = Upload::getInstance();
 }
开发者ID:vberzsin,项目名称:2014,代码行数:5,代码来源:UploadTest.php

示例7: edit

 /**
  * Create or edit an user
  */
 public function edit()
 {
     $user = App::session()->getUser();
     $roles = array_map(function ($role) {
         return $role->getLabel();
     }, Role::getAll('id'));
     $param = array('id' => 'user-profile-form', 'upload' => true, 'object' => $user, 'fieldsets' => array('general' => array('legend' => Lang::get('admin.user-form-general-legend'), new TextInput(array('name' => 'username', 'required' => true, 'label' => Lang::get('admin.user-form-username-label'), 'disabled' => true)), new EmailInput(array('name' => 'email', 'required' => true, 'label' => Lang::get('admin.user-form-email-label')))), 'profile' => array('legend' => Lang::get('admin.user-form-profile-legend')), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get($this->_plugin . '.valid-button'))))), 'onsuccess' => 'app.dialog("close")');
     // Get the user profile questions
     $questions = ProfileQuestion::getAll('name', array(), array('order' => DB::SORT_ASC));
     // Generate the question fields
     foreach ($questions as $question) {
         if ($question->displayInProfile && $question->isAllowedForRole($user->roleId)) {
             $classname = '\\Hawk\\' . ucwords($question->type) . 'Input';
             $field = json_decode($question->parameters, true);
             $field['name'] = $question->name;
             $field['id'] = 'user-form-' . $question->name . '-input';
             $field['independant'] = true;
             $field['label'] = Lang::get('admin.profile-question-' . $question->name . '-label');
             if (isset($field['readonly'])) {
                 if ($field['readonly']) {
                     $field['required'] = false;
                 }
             }
             if ($user) {
                 if ($question->type == "file") {
                     $field['after'] = sprintf('<img src="%s" class="profile-image" />', $user->getProfileData($question->name) ? $user->getProfileData($question->name) : '');
                 } else {
                     $field['default'] = $user->getProfileData($question->name);
                 }
             }
             if ($question->name == 'language') {
                 // Get language options
                 $languages = Language::getAllActive();
                 $options = array();
                 foreach ($languages as $language) {
                     $options[$language->tag] = $language->label;
                 }
                 $field['options'] = $options;
                 if (!$field['default']) {
                     $field['default'] = Option::get($this->_plugin . '.language');
                 }
             }
             $param['fieldsets']['profile'][] = new $classname($field);
         }
     }
     $form = new Form($param);
     if (!$form->submitted()) {
         return NoSidebarTab::make(array('title' => Lang::get('admin.user-form-title'), 'page' => array('content' => $form)));
     } else {
         try {
             foreach ($questions as $question) {
                 if ($question->displayInProfile && $question->isAllowedForRole($user->roleId)) {
                     if ($question->type === 'file') {
                         $upload = Upload::getInstance($question->name);
                         if ($upload) {
                             $file = $upload->getFile(0);
                             $dir = Plugin::current()->getPublicUserfilesDir() . 'img/';
                             $url = Plugin::current()->getUserfilesUrl() . 'img/';
                             if (!is_dir($dir)) {
                                 mkdir($dir, 0755, true);
                             }
                             $basename = uniqid() . $file->extension;
                             $upload->move($file, $dir, $basename);
                             $user->setProfileData($question->name, $url . $basename);
                         }
                     } else {
                         $user->setProfileData($question->name, $form->inputs[$question->name]->dbvalue());
                     }
                 }
             }
             $user->saveProfile();
             if ($form->getData('email') !== $user->email) {
                 // The user asked to reset it email
                 // Check this email is not used by another user on the application
                 $existingUser = User::getByExample(new DBExample(array('id' => array('$ne' => $user->id), 'email' => $form->getData('email'))));
                 if ($existingUser) {
                     return $form->response(Form::STATUS_CHECK_ERROR, Lang::get($this->_plugin . '.reset-email-already-used'));
                 }
                 // Send the email to validate the new email
                 // Create the token to validate the new email
                 $tokenData = array('userId' => $user->id, 'currentEmail' => $user->email, 'newEmail' => $form->getData('email'), 'createTime' => time());
                 $token = base64_encode(Crypto::aes256Encode(json_encode($tokenData)));
                 // Create the email content
                 $emailContent = View::make($this->getPlugin()->getView('change-email-validation.tpl'), array('sitename' => Option::get($this->_plugin . '.sitename'), 'validationUrl' => App::router()->getUrl('validate-new-email', array('token' => $token))));
                 $email = new Mail();
                 $email->to($form->getData('email'))->from(Option::get('main.mailer-from'), Option::get('main.mailer-from-name'))->title(Lang::get($this->_plugin . '.reset-email-title', array('sitename' => Option::get($this->_plugin . '.sitename'))))->content($emailContent)->subject(Lang::get($this->_plugin . '.reset-email-title', array('sitename' => Option::get($this->_plugin . '.sitename'))))->send();
                 return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.user-profile-update-success-with-email'));
             }
             return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.user-profile-update-success'));
         } catch (Exception $e) {
             return $form->response(Form::STATUS_ERROR, Lang::get($this->_plugin . '.user-profile-update-error'));
         }
     }
 }
开发者ID:elvyrra,项目名称:hawk,代码行数:97,代码来源:UserProfileController.php

示例8: register

 /**
  * Register a new user
  */
 public function register()
 {
     $param = array('id' => 'register-form', 'model' => 'User', 'reference' => array('id' => -1), 'fieldsets' => array('global' => array('legend' => Lang::get($this->_plugin . '.register-connection-legend'), new TextInput(array('name' => 'username', 'required' => true, 'unique' => true, 'pattern' => '/^\\w+$/', 'label' => Lang::get($this->_plugin . '.register-username-label'))), new EmailInput(array('name' => 'email', 'required' => true, 'unique' => true, 'label' => Lang::get($this->_plugin . '.register-email-label'))), new PasswordInput(array('name' => 'password', 'required' => true, 'encrypt' => array('\\Hawk\\Crypto', 'saltHash'), 'label' => Lang::get($this->_plugin . '.register-password-label'))), new PasswordInput(array('name' => 'passagain', 'required' => true, 'independant' => true, 'label' => Lang::get($this->_plugin . '.register-passagain-label'), 'compare' => 'password'))), 'profile' => array('legend' => Lang::get($this->_plugin . '.register-profile-legend')), 'terms' => array(Option::get($this->_plugin . '.confirm-register-terms') ? new CheckboxInput(array('name' => 'terms', 'required' => true, 'independant' => true, 'labelWidth' => 'auto', 'label' => Lang::get($this->_plugin . '.register-terms-label', array('uri' => App::router()->getUri('terms'))))) : null), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get($this->_plugin . '.register-button'))), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get($this->_plugin . '.cancel-button'), 'href' => App::router()->getUri('login'), 'target' => 'dialog')))), 'onsuccess' => 'app.dialog(app.getUri("login"))');
     $questions = ProfileQuestion::getRegisterQuestions();
     foreach ($questions as $question) {
         $field = json_decode($question->parameters, true);
         //if(!empty($field->roles) && in_array(Option::get('roles.default-role'), $field->roles)) {
         if ($question->isAllowedForRole(Option::get('roles.default-role'))) {
             $classname = 'Hawk\\' . ucwords($question->type) . 'Input';
             $field['name'] = $question->name;
             $field['independant'] = true;
             $field['label'] = Lang::get('admin.profile-question-' . $question->name . '-label');
             // At register, no field is readonly!
             $field['readonly'] = false;
             $param['fieldsets']['profile'][] = new $classname($field);
         }
     }
     $form = new Form($param);
     if (!$form->submitted()) {
         return Dialogbox::make(array('page' => $form->__toString(), 'icon' => 'sign-in', 'title' => Lang::get($this->_plugin . '.login-form-title'), 'width' => '50rem'));
     } else {
         if ($form->check()) {
             try {
                 $user = new User(array('username' => $form->inputs['username']->dbvalue(), 'email' => $form->inputs['email']->dbvalue(), 'password' => $form->inputs['password']->dbvalue(), 'active' => Option::get($this->_plugin . '.confirm-register-email') ? 0 : 1, 'createTime' => time(), 'createIp' => App::request()->clientIp(), 'roleId' => Option::get('roles.default-role')));
                 $user->save();
                 foreach ($questions as $question) {
                     if ($question->type === 'file') {
                         $upload = Upload::getInstance($question->name);
                         if ($upload) {
                             $file = $upload->getFile(0);
                             $dir = Plugin::current()->getUserfilesDir() . 'img/';
                             $url = Plugin::current()->getUserfilesUrl() . 'img/';
                             if (!is_dir($dir)) {
                                 mkdir($dir, 0755, true);
                             }
                             $upload->move($file, $dir);
                             $user->setProfileData($question->name, $url . $file->basename);
                         }
                     } else {
                         $user->setProfileData($question->name, $form->inputs[$question->name]->dbvalue());
                     }
                 }
                 $user->saveProfile();
                 if (Option::get($this->_plugin . '.confirm-register-email')) {
                     // Send an email to validate the registration
                     $tokenData = array('username' => $user->username, 'email' => $user->email, 'createTime' => $user->createTime, 'createIp' => $user->createIp);
                     $token = Crypto::aes256Encode(json_encode($tokenData));
                     $url = App::router()->getUrl('validate-registration', array('token' => $token));
                     $data = array('themeBaseCss' => Theme::getSelected()->getBaseCssUrl(), 'themeCustomCss' => Theme::getSelected()->getCustomCssUrl(), 'logoUrl' => Option::get($this->_plugin . '.logo') ? Plugin::current()->getUserfilesUrl(Option::get($this->_plugin . '.logo')) : Plugin::current()->getStaticUrl('img/hawk-logo.png'), 'sitename' => Option::get($this->_plugin . '.sitename'), 'url' => $url);
                     if (Option::get($this->_plugin . '.confirm-email-content')) {
                         $mailContent = View::makeFromString(Option::get($this->_plugin . '.confirm-email-content'), $data);
                     } else {
                         $mailContent = View::make(Plugin::current()->getView('registration-validation-email.tpl'), $data);
                     }
                     $mail = new Mail();
                     $mail->from(Option::get($this->_plugin . '.mailer-from'))->fromName(Option::get($this->_plugin . '.mailer-from-name'))->to($user->email)->title(Lang::get('main.register-email-title', array('sitename' => Option::get('main.sitename'))))->content($mailContent)->subject(Lang::get($this->_plugin . '.register-email-title', array('sitename' => Option::get($this->_plugin . '.sitename'))))->send();
                     return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.register-send-email-success'));
                 } else {
                     // validate the registration
                     return $form->response(Form::STATUS_SUCCESS, Lang::get($this->_plugin . '.register-success'));
                 }
             } catch (Exception $e) {
                 return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : Lang::get($this->_plugin . '.register-error'));
             }
         }
     }
 }
开发者ID:elvyrra,项目名称:hawk,代码行数:70,代码来源:LoginController.php


注:本文中的Upload::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。