public function update()
 {
     $f = new Field();
     $f->name = $this->getFieldName();
     $f->type = $this->getFieldType();
     $f->save();
     $this->fieldSetup($f);
     $f->save();
     return $f;
 }
Example #2
0
 /**
  * Save data to the datastore.
  * Manually save the map field data fragments.
  **/
 public function save()
 {
     $name = $this->get_name();
     $value = $this->get_value();
     // Add the "lat" meta in the database
     $this->set_name($name . '-lat');
     $this->set_value($value['lat']);
     $this->store->save($this);
     // Add the "lng" meta in the database
     $this->set_name($name . '-lng');
     $this->set_value($value['lng']);
     $this->store->save($this);
     // Add the "zoom" meta in the database
     $this->set_name($name . '-zoom');
     $this->set_value($value['zoom']);
     $this->store->save($this);
     // Add the "address" meta in the database
     $this->set_name($name . '-address');
     $this->set_value($value['address']);
     $this->store->save($this);
     // Set the value for the field
     $this->set_name($name);
     $field_value = !empty($value['lat']) && !empty($value['lng']) ? $value['lat'] . ',' . $value['lng'] : '';
     $this->set_value($field_value);
     parent::save();
 }
Example #3
0
 /**
  * Handle the case where the user removes the video or
  * just doesn't specify a url path to a video
  *
  * @param  Field 		$field
  * @param  array 		$input
  * @return boolean
  */
 protected function noAudioPathDefined($field, $input)
 {
     $filepath = trim($field->values->original);
     if (!empty($filepath)) {
         return false;
     }
     foreach ($this->formats as $format) {
         $field->values->merge(["{$format}_url" => '']);
     }
     $field->json_value = $field->values->toJSON();
     $field->save();
     return true;
 }
 /**
  * Install all the required fields, templates etc
  *
  * @access public
  *
  */
 public function ___install()
 {
     // Pin Topics / Comments Permission
     if (!$this->fields->get('hbb_p_pin')) {
         $field_topic_pin = new Field();
         $field_topic_pin->type = $this->modules->get("FieldtypePage");
         $field_topic_pin->name = 'hbb_p_pin';
         $field_topic_pin->label = 'Pin Topics / Comments';
         $field_topic_pin->template_id = wire('templates')->get("role")->id;
         // Get the id number of the 'role' template
         $field_topic_pin->labelFieldName = 'name';
         $field_topic_pin->inputfield = 'InputfieldCheckboxes';
         $field_topic_pin->optionColumns = 1;
         $field_topic_pin->tags = 'HermodBB';
         $field_topic_pin->icon = 'thumb-tack';
         $field_topic_pin->save();
     }
     // Lock Topics Permission
     if (!$this->fields->get('hbb_p_topic_lock')) {
         $field_topic_lock = new Field();
         $field_topic_lock->type = $this->modules->get("FieldtypePage");
         $field_topic_lock->name = 'hbb_p_topic_lock';
         $field_topic_lock->label = 'Lock Topics';
         $field_topic_lock->template_id = wire('templates')->get("role")->id;
         // Get the id number of the 'role' template
         $field_topic_lock->labelFieldName = 'name';
         $field_topic_lock->inputfield = 'InputfieldCheckboxes';
         $field_topic_lock->optionColumns = 1;
         $field_topic_lock->tags = 'HermodBB';
         $field_topic_lock->icon = 'lock';
         $field_topic_lock->save();
     }
     // View Forum Permission
     if (!$this->fields->get('hbb_p_forum_view')) {
         $field_forum_view = new Field();
         $field_forum_view->type = $this->modules->get("FieldtypePage");
         $field_forum_view->name = 'hbb_p_forum_view';
         $field_forum_view->label = 'View Forum & Topics';
         $field_forum_view->template_id = wire('templates')->get("role")->id;
         // Get the id number of the 'role' template
         $field_forum_view->labelFieldName = 'name';
         $field_forum_view->inputfield = 'InputfieldCheckboxes';
         $field_forum_view->optionColumns = 1;
         $field_forum_view->tags = 'HermodBB';
         $field_forum_view->icon = 'eye';
         $field_forum_view->save();
     }
     // Start Topics Permission
     if (!$this->fields->get('hbb_p_topic_start')) {
         $field_topic_post = new Field();
         $field_topic_post->type = $this->modules->get("FieldtypePage");
         $field_topic_post->name = 'hbb_p_topic_start';
         $field_topic_post->label = 'Start Topics';
         $field_topic_post->template_id = wire('templates')->get("role")->id;
         // Get the id number of the 'role' template
         $field_topic_post->labelFieldName = 'name';
         $field_topic_post->inputfield = 'InputfieldCheckboxes';
         $field_topic_post->optionColumns = 1;
         $field_topic_post->tags = 'HermodBB';
         $field_topic_post->icon = 'file';
         $field_topic_post->save();
     }
     // View Comments Permission
     if (!$this->fields->get('hbb_p_comments_view')) {
         $field_comments_view = new Field();
         $field_comments_view->type = $this->modules->get("FieldtypePage");
         $field_comments_view->name = 'hbb_p_comments_view';
         $field_comments_view->label = 'View Comments (replies)';
         $field_comments_view->template_id = wire('templates')->get("role")->id;
         // Get the id number of the 'role' template
         $field_comments_view->labelFieldName = 'name';
         $field_comments_view->inputfield = 'InputfieldCheckboxes';
         $field_comments_view->optionColumns = 1;
         $field_comments_view->tags = 'HermodBB';
         $field_comments_view->icon = 'eye';
         $field_comments_view->save();
     }
     // Post Comments Permission
     if (!$this->fields->get('hbb_p_comments_post')) {
         $field_comments_post = new Field();
         $field_comments_post->type = $this->modules->get("FieldtypePage");
         $field_comments_post->name = 'hbb_p_comments_post';
         $field_comments_post->label = 'Post Comments (replies)';
         $field_comments_post->template_id = wire('templates')->get("role")->id;
         // Get the id number of the 'role' template
         $field_comments_post->labelFieldName = 'name';
         $field_comments_post->inputfield = 'InputfieldCheckboxes';
         $field_comments_post->optionColumns = 1;
         $field_comments_post->tags = 'HermodBB';
         $field_comments_post->icon = 'comment';
         $field_comments_post->save();
     }
     // Forum Description
     if (!$this->fields->get('hbb_forum_description')) {
         $field_forum_description = new Field();
         $field_forum_description->type = $this->modules->get("FieldtypeTextarea");
         $field_forum_description->name = 'hbb_forum_description';
         $field_forum_description->label = 'Forum Description / Rules';
         $field_forum_description->tags = 'HermodBB';
         $field_forum_description->icon = 'question-circle';
         $field_forum_description->save();
     }
     // View Forum Cat Permission
     if (!$this->fields->get('hbb_p_forum_cat_view')) {
         $field_forum_cat_view = new Field();
         $field_forum_cat_view->type = $this->modules->get("FieldtypePage");
         $field_forum_cat_view->name = 'hbb_p_forum_cat_view';
         $field_forum_cat_view->label = 'View Forum Category';
         $field_forum_cat_view->template_id = wire('templates')->get("role")->id;
         // Get the id number of the 'role' template
         $field_forum_cat_view->labelFieldName = 'name';
         $field_forum_cat_view->inputfield = 'InputfieldCheckboxes';
         $field_forum_cat_view->optionColumns = 1;
         $field_forum_cat_view->tags = 'HermodBB';
         $field_forum_cat_view->icon = 'eye';
         $field_forum_cat_view->save();
     }
     // Comment Field
     if (!$this->fields->get('hbb_comment_content')) {
         $field_comment = new Field();
         $field_comment->type = $this->modules->get("FieldtypeTextarea");
         $field_comment->name = 'hbb_comment_content';
         $field_comment->label = 'Comment';
         $field_comment->tags = 'HermodBB';
         $field_comment->icon = 'comment';
         $field_comment->save();
     }
     // Comment ID
     if (!$this->fields->get('hbb_comment_id')) {
         $field_id = new Field();
         $field_id->type = $this->modules->get("FieldtypeInteger");
         $field_id->name = 'hbb_comment_id';
         $field_id->label = 'Comment ID';
         $field_id->tags = 'HermodBB';
         $field_id->icon = 'comment';
         $field_id->save();
     }
     // Reply ID
     if (!$this->fields->get('hbb_reply_id')) {
         $field_reply_id = new Field();
         $field_reply_id->type = $this->modules->get("FieldtypeInteger");
         $field_reply_id->name = 'hbb_reply_id';
         $field_reply_id->label = 'Reply ID';
         $field_reply_id->description = 'The $page->id of the comment that was replied to (if applicable)';
         $field_reply_id->tags = 'HermodBB';
         $field_reply_id->icon = 'reply';
         $field_reply_id->save();
     }
     // Author IP
     if (!$this->fields->get('hbb_ip')) {
         $field_ip = new Field();
         $field_ip->type = $this->modules->get("FieldtypeText");
         $field_ip->name = 'hbb_ip';
         $field_ip->label = 'IP Address';
         $field_ip->tags = 'HermodBB';
         $field_ip->icon = 'search';
         $field_ip->save();
     }
     // Author User Agent
     if (!$this->fields->get('hbb_agent')) {
         $field_agent = new Field();
         $field_agent->type = $this->modules->get("FieldtypeText");
         $field_agent->name = 'hbb_agent';
         $field_agent->label = 'User Agent';
         $field_agent->tags = 'HermodBB';
         $field_agent->icon = 'search';
         $field_agent->save();
     }
     // Comment/Topic Date
     if (!$this->fields->get('hbb_date')) {
         $field_date = new Field();
         $field_date->type = $this->modules->get("FieldtypeDatetime");
         $field_date->name = "hbb_date";
         $field_date->label = "Comment / Topic Created";
         $field_date->dateOutputFormat = "U";
         $field_date->dateInputFormat = "j F Y";
         $field_date->timeInputFormat = "g:i A";
         $field_date->defaultToday = 1;
         $field_date->datepicker = 1;
         // datepicker on click
         $field_date->tags = 'HermodBB';
         $field_date->icon = 'calendar';
         $field_date->save();
     }
     // Comment/Topic Edited Date
     if (!$this->fields->get('hbb_edate')) {
         $field_edit_date = new Field();
         $field_edit_date->type = $this->modules->get("FieldtypeDatetime");
         $field_edit_date->name = "hbb_edate";
         $field_edit_date->label = "Comment / Topic Last Edited";
         $field_edit_date->dateOutputFormat = "U";
         $field_edit_date->dateInputFormat = "j F Y";
         $field_edit_date->timeInputFormat = "g:i A";
         $field_edit_date->defaultToday = 1;
         $field_edit_date->datepicker = 1;
         // datepicker on click
         $field_edit_date->tags = 'HermodBB';
         $field_edit_date->icon = 'calendar';
         $field_edit_date->save();
     }
     // Last Reply Date
     if (!$this->fields->get('hbb_ldate')) {
         $field_last_date = new Field();
         $field_last_date->type = $this->modules->get("FieldtypeDatetime");
         $field_last_date->name = "hbb_ldate";
         $field_last_date->label = "Last Reply Date";
         $field_last_date->dateOutputFormat = "U";
         $field_last_date->dateInputFormat = "j F Y";
         $field_last_date->timeInputFormat = "g:i A";
         $field_last_date->defaultToday = 1;
         $field_last_date->datepicker = 1;
         // datepicker on click
         $field_last_date->tags = 'HermodBB';
         $field_last_date->icon = 'calendar';
         $field_last_date->save();
     }
     // Pinned
     if (!$this->fields->get('hbb_pinned')) {
         $field_pinned = new Field();
         $field_pinned->type = $this->modules->get("FieldtypeCheckbox");
         $field_pinned->name = "hbb_pinned";
         $field_pinned->label = "Pinned";
         $field_pinned->autocheck = 0;
         $field_pinned->uncheckedValue = 0;
         $field_pinned->checkedValue = 1;
         $field_pinned->tags = 'HermodBB';
         $field_pinned->icon = 'thumb-tack';
         $field_pinned->save();
     }
     // Private Members
     if (!$this->fields->get('hbb_private_members')) {
         $field_private_members = new Field();
         $field_private_members->type = $this->modules->get("FieldtypePage");
         $field_private_members->name = 'hbb_private_members';
         $field_private_members->label = 'Allowed Members';
         $field_private_members->description = 'Which members are allowed to view this topic? Blank = public';
         $field_private_members->template_id = wire('templates')->get("user")->id;
         // Get the id number of the 'user' template
         $field_private_members->labelFieldName = 'name';
         $field_private_members->inputfield = 'InputfieldAsmSelect';
         $field_private_members->tags = 'HermodBB';
         $field_private_members->icon = 'unlock';
         $field_private_members->save();
     }
     // Topic Viewed
     if (!$this->fields->get('hbb_topic_viewed')) {
         $field_topic_viewed = new Field();
         $field_topic_viewed->type = $this->modules->get("FieldtypePage");
         $field_topic_viewed->name = 'hbb_topic_viewed';
         $field_topic_viewed->label = 'Topic Viewed';
         $field_topic_viewed->description = 'Which members have viewed this topic?';
         $field_topic_viewed->template_id = wire('templates')->get("user")->id;
         // Get the id number of the 'user' template
         $field_topic_viewed->labelFieldName = 'name';
         $field_topic_viewed->inputfield = 'InputfieldSelectMultiple';
         $field_topic_viewed->tags = 'HermodBB';
         $field_topic_viewed->icon = 'eye';
         $field_topic_viewed->save();
     }
     // Locked
     if (!$this->fields->get('hbb_locked')) {
         $field_locked = new Field();
         $field_locked->type = $this->modules->get("FieldtypeCheckbox");
         $field_locked->name = "hbb_locked";
         $field_locked->label = "Locked";
         $field_locked->autocheck = 0;
         $field_locked->uncheckedValue = 0;
         $field_locked->checkedValue = 1;
         $field_locked->tags = 'HermodBB';
         $field_locked->icon = 'lock';
         $field_locked->save();
     }
     // Topic Field
     if (!$this->fields->get('hbb_topic_content')) {
         $field_topic = new Field();
         $field_topic->type = $this->modules->get("FieldtypeTextarea");
         $field_topic->name = 'hbb_topic_content';
         $field_topic->label = 'Topic';
         $field_topic->tags = 'HermodBB';
         $field_topic->icon = 'file';
         $field_topic->save();
     }
     // Comment Fieldgroup
     if (!$this->fieldgroups->get('hbb_comment')) {
         $fg_comment_full = new Fieldgroup();
         $fg_comment_full->name = 'hbb_comment';
         $fg_comment_full->add($this->fields->get('title'));
         $fg_comment_full->add($field_pinned);
         $fg_comment_full->add($field_id);
         $fg_comment_full->add($field_ip);
         $fg_comment_full->add($field_agent);
         $fg_comment_full->add($field_date);
         $fg_comment_full->add($field_edit_date);
         $fg_comment_full->add($field_comment);
         $fg_comment_full->add($field_reply_id);
         $fg_comment_full->save();
     }
     // Comments Category Fieldgroup
     if (!$this->fieldgroups->get('hbb_comment_cat')) {
         $fg_comment_cat = new Fieldgroup();
         $fg_comment_cat->name = 'hbb_comment_cat';
         $fg_comment_cat->add($this->fields->get('title'));
         $fg_comment_cat->save();
     }
     // Topic Fieldgroup
     if (!$this->fieldgroups->get('hbb_topic')) {
         $fg_topic = new Fieldgroup();
         $fg_topic->name = 'hbb_topic';
         $fg_topic->add($this->fields->get('title'));
         $fg_topic->add($field_pinned);
         $fg_topic->add($field_locked);
         $fg_topic->add($field_topic_viewed);
         $fg_topic->add($field_private_members);
         $fg_topic->add($field_ip);
         $fg_topic->add($field_agent);
         $fg_topic->add($field_date);
         $fg_topic->add($field_edit_date);
         $fg_topic->add($field_last_date);
         $fg_topic->add($field_topic);
         $fg_topic->save();
     }
     // Forum Fieldgroup
     if (!$this->fieldgroups->get('hbb_forum')) {
         $fg_forum = new Fieldgroup();
         $fg_forum->name = 'hbb_forum';
         $fg_forum->add($this->fields->get('title'));
         $fg_forum->add($field_forum_description);
         $fg_forum->add($field_forum_view);
         $fg_forum->add($field_topic_post);
         $fg_forum->add($field_comments_view);
         $fg_forum->add($field_comments_post);
         $fg_forum->add($field_topic_pin);
         $fg_forum->add($field_topic_lock);
         $fg_forum->save();
     }
     // Forum Cat Fieldgroup
     if (!$this->fieldgroups->get('hbb_forum_cat')) {
         $fg_forum_cat = new Fieldgroup();
         $fg_forum_cat->name = 'hbb_forum_cat';
         $fg_forum_cat->add($this->fields->get('title'));
         $fg_forum_cat->add($field_forum_cat_view);
         $fg_forum_cat->save();
     }
     // BB / Forum Root Fieldgroup
     if (!$this->fieldgroups->get('hbb_bbroot')) {
         $fg_bbroot = new Fieldgroup();
         $fg_bbroot->name = 'hbb_bbroot';
         $fg_bbroot->add($this->fields->get('title'));
         $fg_bbroot->save();
     }
     // Comment Template
     if (!$this->templates->get('hbb_comment')) {
         $template_comment_full = new Template();
         $template_comment_full->name = 'hbb_comment';
         $template_comment_full->fieldgroup = $fg_comment_full;
         $template_comment_full->label = 'HBB Comment';
         $template_comment_full->icon = 'comment';
         $template_comment_full->tags = 'HermodBB';
         $template_comment_full = $template_comment_full->save();
     }
     // Comments Category Template
     if (!$this->templates->get('hbb_comment_cat')) {
         $template_comment_cat = new Template();
         $template_comment_cat->name = 'hbb_comment_cat';
         $template_comment_cat->fieldgroup = $fg_comment_cat;
         $template_comment_cat->label = 'HBB Comments Category';
         $template_comment_cat->icon = 'comments';
         $template_comment_cat->tags = 'HermodBB';
         $template_comment_cat = $template_comment_cat->save();
     }
     // Topic Template
     if (!$this->templates->get('hbb_topic')) {
         $template_topic = new Template();
         $template_topic->name = 'hbb_topic';
         $template_topic->fieldgroup = $fg_topic;
         $template_topic->label = 'HBB Topic';
         $template_topic->icon = 'file';
         $template_topic->tags = 'HermodBB';
         $template_topic = $template_topic->save();
     }
     // Forum Template
     if (!$this->templates->get('hbb_forum')) {
         $template_forum = new Template();
         $template_forum->name = 'hbb_forum';
         $template_forum->fieldgroup = $fg_forum;
         $template_forum->label = 'HBB Forum';
         $template_forum->icon = 'folder-open';
         $template_forum->tags = 'HermodBB';
         $template_forum->allowPageNum = 1;
         $template_forum->childTemplates = array(wire('templates')->get("hbb_topic")->id);
         $template_forum = $template_forum->save();
     }
     // Forum Cat Template
     if (!$this->templates->get('hbb_forum_cat')) {
         $template_forum_cat = new Template();
         $template_forum_cat->name = 'hbb_forum_cat';
         $template_forum_cat->fieldgroup = $fg_forum_cat;
         $template_forum_cat->label = 'HBB Forum Category';
         $template_forum_cat->icon = 'folder';
         $template_forum_cat->tags = 'HermodBB';
         $template_forum_cat->childTemplates = array(wire('templates')->get("hbb_forum")->id);
         $template_forum_cat = $template_forum_cat->save();
     }
     // BB / Forum Root Template
     if (!$this->templates->get('hbb_bbroot')) {
         $template_bbroot = new Template();
         $template_bbroot->name = 'hbb_bbroot';
         $template_bbroot->fieldgroup = $fg_bbroot;
         $template_bbroot->label = 'HBB Forum Root';
         $template_bbroot->icon = 'sitemap';
         $template_bbroot->tags = 'HermodBB';
         $template_bbroot->childTemplates = array(wire('templates')->get("hbb_forum_cat")->id);
         $template_bbroot = $template_bbroot->save();
     }
 }
 public function install(array $settings)
 {
     $field = $this->fields->get('email_images');
     if (!$field) {
         $field = new Field();
         $field->name = 'email_images';
         $field->type = $this->modules->get('FieldtypeImage');
         $field->label = 'Email Images';
         $field->extensions = 'jpeg jpg gif png';
         $field->maxFiles = 0;
         $field->unzip = 0;
         $field->descriptionRows = 1;
         $field->entityEncode = 1;
         $field->save();
         $this->message("Created field: {$field->name}");
     }
     $settings['images_field_id'] = $field->id;
     $field2 = $this->fields->get('email_image_body');
     if (!$field2) {
         $field2 = new Field();
         $field2->name = 'email_image_body';
         $field2->type = $this->modules->get('FieldtypeTextarea');
         $field2->label = 'Body Text';
         $field2->textformatters = array('TextformatterEntities');
         $field2->inputfieldClass = 'InputfieldTextarea';
         $field2->rows = 5;
         $field2->save();
         $this->message("Created field: {$field2->name}");
     }
     // parent fieldgroup
     $parentFieldgroup = $this->fieldgroups->get('email-images');
     if (!$parentFieldgroup) {
         $parentFieldgroup = new Fieldgroup();
         $parentFieldgroup->name = 'email-images';
         $parentFieldgroup->save();
         $parentFieldgroup->add('title');
         $parentFieldgroup->save();
         $this->message("Created fieldgroup: {$parentFieldgroup->name}");
     }
     // parent template
     $parentTemplate = $this->templates->get('email-images');
     if (!$parentTemplate) {
         $parentTemplate = new Template();
         $parentTemplate->name = 'email-images';
         $parentTemplate->fieldgroup = $parentFieldgroup;
         $parentTemplate->allowPageNum = 1;
         $parentTemplate->save();
         $this->message("Created template: {$parentTemplate->name}");
     }
     $settings['parent_template_id'] = $parentTemplate->id;
     // child fieldgroup
     $childFieldgroup = $this->fieldgroups->get('email-image');
     if (!$childFieldgroup) {
         $childFieldgroup = new Fieldgroup();
         $childFieldgroup->name = 'email-image';
         $childFieldgroup->save();
         $childFieldgroup->add('title');
         $childFieldgroup->add($field);
         // email_images
         $childFieldgroup->add($field2);
         // email_image_body
         $childFieldgroup->save();
         $this->message("Created fieldgroup: {$childFieldgroup->name}");
     }
     // child template
     $childTemplate = $this->templates->get('email-image');
     if (!$template) {
         $childTemplate = new Template();
         $childTemplate->name = 'email-image';
         $childTemplate->fieldgroup = $childFieldgroup;
         $childTemplate->noChildren = 1;
         $childTemplate->parentTemplates = array($parentTemplate->id);
         $childTemplate->save();
         $this->message("Created template: {$childTemplate->name}");
     }
     $settings['child_template_id'] = $childTemplate->id;
     $parentPage = $this->pages->get('/email-images/');
     if (!$parentPage->id) {
         $parentPage = new Page();
         $parentPage->template = $parentTemplate;
         $parentPage->parent = '/';
         $parentPage->name = 'email-images';
         $parentPage->title = 'Email Images';
         $parentPage->addStatus(Page::statusHidden);
         $parentPage->sortfield = '-created';
         $parentPage->save();
         $this->message("Created page: {$parentPage->path}");
     }
     $settings['parent_page_id'] = $parentPage->id;
     // update settings for parentTemplate
     $parentTemplate->childTemplates = array($childTemplate->id);
     $parentTemplate->noParents = 1;
     $parentTemplate->save();
     $this->modules->saveModuleConfigData('EmailImage', $settings);
     // install template file
     if (is_writable(wire('config')->paths->templates)) {
         if (@copy(dirname(__FILE__) . '/email-images.php', wire('config')->paths->templates . 'email-images.php')) {
             $this->message("Installed template file: email-images.php");
         }
     }
 }
 /**
  * Install the module and related modules
  *
  */
 public function ___install()
 {
     $configData = array();
     if ($this->templates->get(LanguageSupport::languageTemplateName)) {
         throw new WireException("There is already a template installed called 'language'");
     }
     if ($this->fields->get(LanguageSupport::languageFieldName)) {
         throw new WireException("There is already a field installed called 'language'");
     }
     $adminPage = $this->pages->get($this->config->adminRootPageID);
     $setupPage = $adminPage->child("name=setup");
     if (!$setupPage->id) {
         throw new WireException("Unable to locate {$adminPage->path}setup/");
     }
     // create the languages parent page
     $languagesPage = new Page();
     $languagesPage->parent = $setupPage;
     $languagesPage->template = $this->templates->get('admin');
     $languagesPage->process = $this->modules->get('ProcessLanguage');
     // INSTALL ProcessLanguage module
     $this->message("Installed ProcessLanguage");
     $languagesPage->name = 'languages';
     $languagesPage->title = 'Languages';
     $languagesPage->status = Page::statusSystem;
     $languagesPage->sort = $setupPage->numChildren;
     $languagesPage->save();
     $configData['languagesPageID'] = $languagesPage->id;
     // create the 'language_files' field used by the 'language' fieldgroup
     $field = new Field();
     $field->type = $this->modules->get("FieldtypeFile");
     $field->name = 'language_files';
     $field->label = 'Language Translation Files';
     $field->extensions = 'json';
     $field->maxFiles = 0;
     $field->inputfieldClass = 'InputfieldFile';
     $field->unzip = 1;
     $field->descriptionRows = 1;
     $field->flags = Field::flagSystem | Field::flagPermanent;
     $field->save();
     $this->message("Created field: language_files");
     // create the fieldgroup to be used by the language template
     $fieldgroup = new Fieldgroup();
     $fieldgroup->name = LanguageSupport::languageTemplateName;
     $fieldgroup->add($this->fields->get('title'));
     $fieldgroup->add($field);
     // language_files
     $fieldgroup->save();
     $this->message("Created fieldgroup: " . LanguageSupport::languageTemplateName . " ({$fieldgroup->id})");
     // create the template used by Language pages
     $template = new Template();
     $template->name = LanguageSupport::languageTemplateName;
     $template->fieldgroup = $fieldgroup;
     $template->parentTemplates = array($adminPage->template->id);
     $template->slashUrls = 1;
     $template->pageClass = 'Language';
     $template->pageLabelField = 'name';
     $template->noGlobal = 1;
     $template->noMove = 1;
     $template->noTrash = 1;
     $template->noUnpublish = 1;
     $template->noChangeTemplate = 1;
     $template->nameContentTab = 1;
     $template->flags = Template::flagSystem;
     $template->save();
     $this->message("Created Template: " . LanguageSupport::languageTemplateName);
     // create the default language page
     $default = new Language();
     $default->template = $template;
     $default->parent = $languagesPage;
     $default->name = 'default';
     $default->title = 'Default';
     $default->status = Page::statusSystem;
     $default->save();
     $configData['defaultLanguagePageID'] = $default->id;
     $configData['otherLanguagePageIDs'] = array();
     // non-default language IDs placeholder
     $this->message("Created Default Language Page: {$default->path}");
     // create the translator page and process
     $translatorPage = new Page();
     $translatorPage->parent = $setupPage;
     $translatorPage->template = $this->templates->get('admin');
     $translatorPage->status = Page::statusHidden | Page::statusSystem;
     $translatorPage->process = $this->modules->get('ProcessLanguageTranslator');
     // INSTALL ProcessLanguageTranslator
     $this->message("Installed ProcessLanguageTranslator");
     $translatorPage->name = 'language-translator';
     $translatorPage->title = 'Language Translator';
     $translatorPage->save();
     $configData['languageTranslatorPageID'] = $translatorPage->id;
     $this->message("Created Language Translator Page: {$translatorPage->path}");
     // save the module config data
     $this->modules->saveModuleConfigData('LanguageSupport', $configData);
     // install 'language' field that will be added to the user fieldgroup
     $field = new Field();
     $field->type = $this->modules->get("FieldtypePage");
     $field->name = LanguageSupport::languageFieldName;
     $field->label = 'Language';
     $field->derefAsPage = 1;
     $field->parent_id = $languagesPage->id;
     $field->labelFieldName = 'title';
     $field->inputfield = 'InputfieldRadios';
     $field->required = 1;
     $field->flags = Field::flagSystem | Field::flagPermanent;
     $field->save();
     $this->message("Created Langage Field: " . LanguageSupport::languageFieldName);
     // make the 'language' field part of the profile fields the user may edit
     $profileConfig = $this->modules->getModuleConfigData('ProcessProfile');
     $profileConfig['profileFields'][] = 'language';
     $this->modules->saveModuleConfigData('ProcessProfile', $profileConfig);
     // add to 'user' fieldgroup
     $userFieldgroup = $this->templates->get('user')->fieldgroup;
     $userFieldgroup->add($field);
     $userFieldgroup->save();
     $this->message("Added field 'language' to user profile");
     // update all users to have the default value set for this field
     $n = 0;
     foreach ($this->users as $user) {
         $user->set('language', $default);
         $user->save();
         $n++;
     }
     $this->message("Added default language to {$n} user profiles");
     $this->message("Language Support Installed! Click to the 'Setup' menu to begin defining languages.");
 }
 /**
  * Commit changed field data 
  *
  */
 protected function ___processImport()
 {
     $data = $this->session->get('FieldImportData');
     if (!$data) {
         throw new WireException("Invalid import data");
     }
     $numChangedFields = 0;
     $numAddedFields = 0;
     $skipFieldNames = array();
     // iterate through data for each field
     foreach ($data as $name => $fieldData) {
         $name = $this->wire('sanitizer')->fieldName($name);
         if (!$this->input->post("import_field_{$name}")) {
             $skipFieldNames[] = $name;
             unset($data[$name]);
             continue;
         }
         $field = $this->wire('fields')->get($name);
         if (!$field) {
             $new = true;
             $field = new Field();
             $field->name = $name;
         } else {
             $new = false;
         }
         unset($fieldData['id']);
         foreach ($fieldData as $property => $value) {
             if (!in_array($property, $this->input->post("field_{$name}"))) {
                 unset($fieldData[$property]);
             }
         }
         try {
             $changes = $field->setImportData($fieldData);
             foreach ($changes as $key => $info) {
                 $this->message($this->_('Saved:') . " {$name}.{$key} => {$info['new']}");
             }
             $field->save();
             if ($new) {
                 $numAddedFields++;
                 $this->message($this->_('Added field') . ' - ' . $name);
             } else {
                 $numChangedFields++;
                 $this->message($this->_('Modified field') . ' - ' . $name);
             }
         } catch (Exception $e) {
             $this->error($e->getMessage());
         }
         $data[$name] = $fieldData;
     }
     $this->session->set('FieldImportSkipNames', $skipFieldNames);
     $this->session->set('FieldImportData', $data);
     $numSkippedFields = count($skipFieldNames);
     if ($numAddedFields) {
         $this->message(sprintf($this->_n('Added %d field', 'Added %d fields', $numAddedFields), $numAddedFields));
     }
     if ($numChangedFields) {
         $this->message(sprintf($this->_n('Modified %d field', 'Modified %d fields', $numChangedFields), $numChangedFields));
     }
     if ($numSkippedFields) {
         $this->message(sprintf($this->_n('Skipped %d field', 'Skipped %d fields', $numSkippedFields), $numSkippedFields));
     }
     $this->session->redirect("./?verify=1");
 }
Example #8
0
    /**
     * Create a new field and save it to database
     * @param sfWebRequest $request
     * @return <type>
     */
    public function executeSaveField(sfWebRequest $request) {
        $data = $request->getPostParameters();
        $fieldClass = new FieldClass();
        $data = $fieldClass->prepareSaveData($data); // prepare the data to save, set color and writeprotected flag

        // create parent element for the fields
        $fieldObj = new Field();
        $fieldObj->setTitle($data['createFileWindow_fieldname']);
        $fieldObj->setType($data['createFileWindow_fieldtype']);
        $fieldObj->setwriteprotected($data['createFileWindow_writeprotected']);
        $fieldObj->setColor($data['createFileWindow_color']);
        $fieldObj->save();
        $id = $fieldObj->getId();

        // add the child elements to the field, with the selected field type
        switch ($data['createFileWindow_fieldtype']) {
            case 'TEXTFIELD':
                $textfield = new FieldTextfield();
                $textfield->setFieldId($id);
                $textfield->setRegex($data['fieldTextfield_regularexpression']);
                $textfield->setDefaultvalue($data['fieldTextfield_standard']);
                $textfield->save();
                break;
            case 'CHECKBOX':
                // do nothing
                break;
            case 'NUMBER':
                $numberfield = new FieldNumber();
                $numberfield->setRegex($data['fieldNumber_regularexpression']);
                $numberfield->setDefaultvalue($data['fieldNumber_standard']);
                $numberfield->setComboboxvalue($data['fieldNumber_regularexpressioncombo']);
                $numberfield->setFieldId($id);
                $numberfield->save();
                break;
            case 'DATE':
                $datefield = new FieldDate();
                $datefield->setRegex($data['fieldDate_regularexpression']);
                $datefield->setDateformat($data['fieldDate_format']);
                $datefield->setDefaultvalue($data['fieldDate_date']);
                $datefield->setFieldId($id);
                $datefield->save();
                break;
            case 'TEXTAREA':
                $data['fieldTextarea_content'] = $data['fieldTextarea_contenttype'] == 'plain' ? $data['fieldTextarea_textarea']: $data['fieldTextarea_htmlarea'];
                $textarea = new FieldTextarea();
                $textarea->setContent($data['fieldTextarea_content']);
                $textarea->setContenttype($data['fieldTextarea_contenttype']);
                $textarea->setFieldId($id);
                $textarea->save();
                break;
            case 'RADIOGROUP':
                $fieldClass->saveRadiogroup($id, $data); // save radiogroup
                break;
            case 'CHECKBOXGROUP':
                $fieldClass->saveCheckboxgroup($id, $data); // save checkboxgroup
                break;
            case 'COMBOBOX':
                $fieldClass->saveCombobox($id, $data); // save combobox
                break;
            case 'FILE':
                $file = new FieldFile();
                $file->setRegex($data['fieldFile_regularexpression']);
                $file->setFieldId($id);
                $file->save();
                break;
        }
        $this->renderText('{success:true}');
        return sfView::NONE;
    }
Example #9
0
 /**
  * Get or create field if not exists
  * 
  * @param int $category_id
  * @param string $fieldName
  * @return \Field 
  */
 public function createIfNotExists($category_id, $fieldName, $createAttributes = array())
 {
     $field = Field::model()->findSingleByAttributes(array('category_id' => $category_id, 'name' => $fieldName));
     if (!$field) {
         $field = new Field();
         $field->setAttributes($createAttributes, false);
         $field->category_id = $category_id;
         $field->name = $fieldName;
         $field->save();
     }
     return $field;
 }
 public function addFilesFields($fieldgroup)
 {
     // create the 'language_files_site' field used by the 'language' fieldgroup
     $field = $this->wire('fields')->get('language_files_site');
     if (!$field) {
         $field = new Field();
         $field->type = $this->modules->get("FieldtypeFile");
         $field->name = 'language_files_site';
         $field->label = 'Site Translation Files';
         $field->extensions = 'json';
         $field->maxFiles = 0;
         $field->inputfieldClass = 'InputfieldFile';
         $field->unzip = 1;
         $field->flags = Field::flagSystem | Field::flagPermanent;
         $field->save();
         $this->message("Created field: language_files_site");
     }
     // update
     $field->label = 'Site Translation Files';
     $field->description = 'Use this for field for translations specific to your site (like files in /site/templates/ for example).';
     $field->descriptionRows = 0;
     $field->save();
     $fieldgroup->add($field);
     // create the 'language_files' field used by the 'language' fieldgroup
     $field = $this->wire('fields')->get('language_files');
     if (!$field) {
         $field = new Field();
         $field->type = $this->modules->get("FieldtypeFile");
         $field->name = 'language_files';
         $field->label = 'Core Translation Files';
         $field->extensions = 'json';
         $field->maxFiles = 0;
         $field->inputfieldClass = 'InputfieldFile';
         $field->unzip = 1;
         $field->flags = Field::flagSystem | Field::flagPermanent;
         $field->save();
         $this->message("Created field: language_files");
     }
     // update
     $field->label = 'Core Translation Files';
     $field->description = 'Use this for field for [language packs](http://modules.processwire.com/categories/language-pack/). To delete all files, double-click the trash can for any file, then save.';
     $field->descriptionRows = 0;
     $field->save();
     $fieldgroup->add($field);
     $fieldgroup->save();
 }
Example #11
0
 /**
  * Install the admin theme
  *
  * Other admin themes using an install() method must call this install before their own.
  *
  */
 public function ___install()
 {
     // if we are the only admin theme installed, no need to add an admin_theme field
     if (self::$numAdminThemes == 0) {
         return;
     }
     // install a field for selecting the admin theme from the user's profile
     $field = $this->wire('fields')->get('admin_theme');
     $toUseNote = $this->_('To use this theme, select it from your user profile.');
     // we already have this field installed, no need to continue
     if ($field) {
         $this->message($toUseNote);
         return;
     }
     // this will be the 2nd admin theme installed, so add a field that lets them select admin theme
     $field = new Field();
     $field->name = 'admin_theme';
     $field->type = $this->wire('modules')->get('FieldtypeModule');
     $field->set('moduleTypes', array('AdminTheme'));
     $field->set('labelField', 'title');
     $field->set('inputfieldClass', 'InputfieldRadios');
     $field->label = 'Admin Theme';
     $field->flags = Field::flagSystem;
     $field->save();
     $fieldgroup = $this->wire('fieldgroups')->get('user');
     $fieldgroup->add($field);
     $fieldgroup->save();
     // make this field one that the user is allowed to configure in their profile
     $data = $this->wire('modules')->getModuleConfigData('ProcessProfile');
     $data['profileFields'][] = 'admin_theme';
     $this->wire('modules')->saveModuleConfigData('ProcessProfile', $data);
     $this->message($this->_('Installed field "admin_theme" and added to user profile settings.'));
     $this->message($toUseNote);
 }