public function activateForumEvent($runData) { $site = $runData->getTemp("site"); $db = Database::connection(); $db->begin(); // copy forum settings from template $c = new Criteria(); $c->add("unix_name", "template-" . $site->getLanguage()); $templateSite = DB_SitePeer::instance()->selectOne($c); $fs = $templateSite->getForumSettings(); $fs->setNew(true); $fs->setSiteId($site->getSiteId()); $fs->save(); // create extra categories? no. // copy pages $d = new Duplicator(); $d->setOwner($runData->getUser()); // copy "forum" category $fc = DB_CategoryPeer::instance()->selectByName("forum", $templateSite->getSiteId()); $d->duplicateCategory($fc, $site); // recompile category. $od = new Outdater(); $od->recompileCategory(DB_CategoryPeer::instance()->selectByName("forum", $site->getSiteId())); // create a "Hidden" forum group and "Deleted" category $group = new DB_ForumGroup(); $group->setSiteId($site->getSiteId()); $group->setName("Hidden"); $group->setVisible(false); $group->save(); $del = new DB_ForumCategory(); $del->setSiteId($site->getSiteId()); $del->setName(_("Deleted threads")); $del->setDescription(_("Deleted forum discussions should go here.")); $del->setPermissions("t:;p:;e:;s:"); $del->setGroupId($group->getGroupId()); $del->save(); $category = new DB_ForumCategory(); $category->setName(_("Per page discussions")); $category->setDescription(_("This category groups discussions related to particular pages within this site.")); $category->setPerPageDiscussion(true); $category->setSiteId($site->getSiteId()); $category->setGroupId($group->getGroupId()); $category->save(); $db->commit(); if (GlobalProperties::$UI_SLEEP) { sleep(1); } }
protected function appendFilter(Duplicator $duplicator, $handle, $name, $value = NULL) { $document = $duplicator->ownerDocument; if (is_null($value)) { $item = $duplicator->createTemplate($name); } else { $item = $duplicator->createInstance($name); } $group = $document->createElement('div'); $group->setAttribute('class', 'group double'); // Value $label = $document->createElement('label', __('Value')); $input = Widget::Input('fields[filters][' . $handle . ']'); if (!is_null($value)) { $input->setAttribute("value", $value); } $label->appendChild($input); $group->appendChild($label); $group->appendChild($label); $item->appendChild($group); }
protected function appendDuplicator(SymphonyDOMElement $wrapper, Section $section, array $items = null) { $document = $wrapper->ownerDocument; $duplicator = new Duplicator(__('Add Item')); $duplicator->addClass('context context-' . $section->handle); $item = $duplicator->createTemplate(__('Override')); $label = Widget::Label(__('Field')); $options = array(array('system:id', false, 'System ID')); foreach ($section->fields as $f) { $options[] = array(General::sanitize($f->{'element-name'}), false, General::sanitize($f->{'publish-label'})); } $label->appendChild(Widget::Select('fields[overrides][field][]', $options)); $item->appendChild($label); $label = Widget::Label(__('Replacement')); $label->appendChild(Widget::Input('fields[overrides][replacement][]')); $item->appendChild($label); $item = $duplicator->createTemplate(__('Default Value')); $label = Widget::Label(__('Field')); $options = array(array('system:id', false, 'System ID')); foreach ($section->fields as $f) { $options[] = array(General::sanitize($f->{'element-name'}), false, General::sanitize($f->{'publish-label'})); } $label->appendChild(Widget::Select('fields[defaults][field][]', $options)); $item->appendChild($label); $label = Widget::Label(__('Replacement')); $label->appendChild(Widget::Input('fields[defaults][replacement][]')); $item->appendChild($label); if (is_array($items['overrides'])) { foreach ($items['overrides'] as $field_name => $replacement) { $item = $duplicator->createInstance(__('Override')); $label = Widget::Label(__('Field')); $options = array(array('system:id', false, __('System ID'))); foreach ($section->fields as $f) { $options[] = array(General::sanitize($f->{'element-name'}), $f->{'element-name'} == $field_name, General::sanitize($f->{'publish-label'})); } $label->appendChild(Widget::Select('fields[overrides][field][]', $options)); $item->appendChild($label); $label = Widget::Label(__('Replacement')); $label->appendChild(Widget::Input('fields[overrides][replacement][]', General::sanitize($replacement))); $item->appendChild($label); } } if (is_array($items['defaults'])) { foreach ($items['defaults'] as $field_name => $replacement) { $item = $duplicator->createInstance(__('Default Value')); $label = Widget::Label(__('Field')); $options = array(array('system:id', false, __('System ID'))); foreach ($section->fields as $f) { $options[] = array(General::sanitize($f->{'element-name'}), $f->{'element-name'} == $field_name, General::sanitize($f->{'publish-label'})); } $label->appendChild(Widget::Select('fields[defaults][field][]', $options)); $item->appendChild($label); $label = Widget::Label(__('Replacement')); $label->appendChild(Widget::Input('fields[defaults][replacement][]', General::sanitize($replacement))); $item->appendChild($label); } } $duplicator->appendTo($wrapper); }
public function createSiteEvent($runData) { WDPermissionManager::instance()->canBecomeAdmin($runData->getUser()); $pl = $runData->getParameterList(); $name = trim($pl->getParameterValue("name")); $unixName = trim($pl->getParameterValue("unixname")); $tagline = trim($pl->getParameterValue("tagline")); $templateId = $pl->getParameterValue("template"); $private = (bool) $pl->getParameterValue("private"); // validate form data: $errors = array(); if (strlen($name) < 1) { $errors['name'] = _("Site name must be present."); } elseif (strlen8($name) > 30) { $errors['name'] = _("Site name should not be longer than 30 characters."); } // site unix name ************* if ($unixName === null || strlen($unixName) < 3) { $errors['unixname'] = _("Web address must be present and should be at least 3 characters long."); } elseif (strlen($unixName) > 30) { $errors['unixname'] = _("Web address name should not be longer than 30 characters."); } elseif (preg_match("/^[a-z0-9\\-]+\$/", $unixName) == 0) { $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address.'); } elseif (preg_match("/\\-\\-/", $unixName) !== 0) { $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address. Double-dash (--) is not allowed.'); } else { $unixName = WDStringUtils::toUnixName($unixName); if (!$runData->getUser()->getSuperAdmin()) { // handle forbidden names $forbiddenUnixNames = explode("\n", file_get_contents(WIKIDOT_ROOT . '/conf/forbidden_site_names.conf')); foreach ($forbiddenUnixNames as $f) { if (preg_match($f, $unixName) > 0) { $errors['unixname'] = _('For some reason this web address is not allowed or is reserved for future use.'); } } } // check if the domain is not taken. $c = new Criteria(); $c->add("unix_name", $unixName); $ss = DB_SitePeer::instance()->selectOne($c); if ($ss) { $errors['unixname'] = _('Sorry, this web address is already used by another site.'); } } // template if (!$templateId) { $errors['template'] = _('Please choose a template for your site'); } if (strlen8($tagline) > 50) { $errors['tagline'] = _("Tagline should not be longer than 50 characters"); } // TOS if (!$pl->getParameterValue("tos")) { $errors['tos'] = _("Please read and agree to the Terms of Service."); } if (count($errors) > 0) { $runData->ajaxResponseAdd("formErrors", $errors); throw new ProcessException("Form errors", "form_errors"); } // and now... CREATE THE SITE!!!!!!!!!!!!!!!! $dup = new Duplicator(); $dup->setOwner($runData->getUser()); $db = Database::connection(); $db->begin(); $templateSite = DB_SitePeer::instance()->selectByPrimaryKey($templateId); if (!preg_match(';^template\\-;', $templateSite->getUnixName())) { throw new ProcessException('Error'); } $site = new DB_Site(); $site->setName($name); $site->setSubtitle($tagline); $site->setUnixName($unixName); $site->setLanguage($templateSite->getLanguage()); $site->setDateCreated(new ODate()); $site->setPrivate($private); if ($private) { // change file flag too $flagDir = WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName() . '/flags'; $flagFile = $flagDir . '/private'; mkdirfull($flagDir); //just to make sure if (!file_exists($flagFile)) { file_put_contents($flagFile, "private"); } } $site->save(); $dup->addExcludedCategory("forum"); // should be initialized independently $dup->addExcludedCategory("profile"); $dup->duplicateSite($templateSite, $site); // index the site too $ind = Indexer::instance(); $c = new Criteria(); $c->add("site_id", $site->getSiteId()); $pages = DB_PagePeer::instance()->select($c); foreach ($pages as $p) { $ind->indexPage($p); } $db->commit(); // clear captcha code $runData->sessionDel("captchaCode"); $runData->ajaxResponseAdd("siteUnixName", $unixName); }
private function __form(Section $existing = null) { // Status message: $callback = Administration::instance()->getPageCallback(); if (isset($callback['flag']) && !is_null($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('Section updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/sections/new/', ADMIN_URL . '/blueprints/sections/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('Section created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/sections/new/', ADMIN_URL . '/blueprints/sections/')), AlertStack::SUCCESS); break; } } if (!$this->alerts()->valid() and $existing instanceof Section) { $this->appendSyncAlert(); } $layout = new Layout(); $left = $layout->createColumn(Layout::SMALL); $right = $layout->createColumn(Layout::LARGE); $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Sections')))); $this->appendSubheading($existing instanceof Section ? $existing->name : __('New Section')); if ($existing instanceof Section) { $this->appendViewOptions(); } // Essentials: $fieldset = $this->createElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild($this->createElement('h3', __('Essentials'))); $label = Widget::Label('Name'); $label->appendChild(Widget::Input('essentials[name]', $this->section->name)); $fieldset->appendChild(isset($this->errors->name) ? Widget::wrapFormElementWithError($label, $this->errors->name) : $label); $label = Widget::Label(__('Navigation Group')); $label->appendChild($this->createElement('em', __('Created if does not exist'))); $label->appendChild(Widget::Input('essentials[navigation-group]', $this->section->{"navigation-group"})); $fieldset->appendChild(isset($this->errors->{'navigation-group'}) ? Widget::wrapFormElementWithError($label, $this->errors->{'navigation-group'}) : $label); $navigation_groups = Section::fetchUsedNavigationGroups(); if (is_array($navigation_groups) && !empty($navigation_groups)) { $ul = $this->createElement('ul', NULL, array('class' => 'tags singular')); foreach ($navigation_groups as $g) { $ul->appendChild($this->createElement('li', $g)); } $fieldset->appendChild($ul); } $input = Widget::Input('essentials[hidden-from-publish-menu]', 'yes', 'checkbox', $this->section->{'hidden-from-publish-menu'} == 'yes' ? array('checked' => 'checked') : array()); $label = Widget::Label(__('Hide this section from the Publish menu')); $label->prependChild($input); $fieldset->appendChild($label); $left->appendChild($fieldset); // Fields $fieldset = $this->createElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild($this->createElement('h3', __('Fields'))); $div = $this->createElement('div'); $h3 = $this->createElement('h3', __('Fields')); $h3->setAttribute('class', 'label'); $div->appendChild($h3); $duplicator = new Duplicator(__('Add Field')); $duplicator->setAttribute('id', 'section-duplicator'); $fields = $this->section->fields; $types = array(); foreach (new FieldIterator() as $pathname) { $type = preg_replace(array('/^field\\./', '/\\.php$/'), NULL, basename($pathname)); $types[$type] = Field::load($pathname); } // To Do: Sort this list based on how many times a field has been used across the system uasort($types, create_function('$a, $b', 'return strnatcasecmp($a->name(), $b->name());')); if (is_array($types)) { foreach ($types as $type => $field) { $defaults = array(); $field->findDefaultSettings($defaults); $field->section = $this->section->handle; foreach ($defaults as $key => $value) { $field->{$key} = $value; } $item = $duplicator->createTemplate($field->name()); $field->displaySettingsPanel($item, new MessageStack()); } } if (is_array($fields)) { foreach ($fields as $position => $field) { $field->sortorder = $position; if ($this->errors->{"field::{$position}"}) { $messages = $this->errors->{"field::{$position}"}; } else { $messages = new MessageStack(); } $item = $duplicator->createInstance($field->name, $field->name()); $field->displaySettingsPanel($item, $messages); } } $duplicator->appendTo($fieldset); $right->appendChild($fieldset); $layout->appendTo($this->Form); $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : 'Create Section', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this section')))); } $this->Form->appendChild($div); }
protected function appendCondition(Duplicator $duplicator, $condition = array()) { $document = $duplicator->ownerDocument; if (empty($condition)) { $item = $duplicator->createTemplate(__('Don\'t Execute When')); } else { $item = $duplicator->createInstance(__('Don\'t Execute When')); } if (!isset($condition['parameter'])) { $condition['parameter'] = null; } if (!isset($condition['logic'])) { $condition['logic'] = 'empty'; } $group = $document->createElement('div'); $group->setAttribute('class', 'group double'); // Parameter $label = $document->createElement('label', __('Parameter')); $label->appendChild(Widget::input('fields[conditions][parameter][]', $condition['parameter'])); $group->appendChild($label); // Logic $label = $document->createElement('label', __('Logic')); $label->appendChild(Widget::select('fields[conditions][logic][]', array(array('empty', $condition['logic'] == 'empty', __('is empty')), array('set', $condition['logic'] == 'set', __('is set'))), array('class' => 'filtered'))); $group->appendChild($label); $group->appendChild($label); $item->appendChild($group); }
public function finalizeEvent($runData, $skipEvcode = false) { // get the form data $pl = $runData->getParameterList(); if (!$skipEvcode) { $evcode = $pl->getParameterValue("evcode", "AMODULE"); //check if the email vercode is correct $evcode2 = $runData->sessionGet('evcode'); if ($evcode !== $evcode2) { throw new ProcessException(_("Invalid email verification code."), "invalid_code"); } } $data = $runData->sessionGet("ca_data"); $name = $data['name']; $email = $data['email']; $password = $data['password']; $lang = $data['language']; $db = Database::connection(); $db->begin(); // check again if email and nick are not duplicate! $c = new Criteria(); $c->add("lower(email)", strtolower($email)); $u = DB_OzoneUserPeer::instance()->selectOne($c); if ($u != null) { $runData->resetSession(); throw new ProcessException(_("A user with this email already exists. Must have been created meanwhile... " . "Unfortunately you have to repeat the whole procedure. :-("), "user_exists"); } $unixified = WDStringUtils::toUnixName($name); $c = new Criteria(); $c->add("unix_name", $unixified); $u = DB_OzoneUserPeer::instance()->selectOne($c); if ($u != null) { $runData->resetSession(); throw new ProcessException(_("A user with this name (or very similar) already exists. Must have been created meanwhile... " . "Unfortunately you have to repeat the whole procedure. :-("), "user_exists"); } // add new user!!! $nuser = new DB_OzoneUser(); /* email as the username!!! */ $nuser->setName($email); $nuser->setEmail($email); $nuser->setPassword(md5($password)); $nuser->setNickName($name); $nuser->setUnixName($unixified); $nuser->setLanguage($lang); $date = new ODate(); $nuser->setRegisteredDate($date); $nuser->setLastLogin($date); $nuser->save(); // profile $profile = new DB_Profile(); $profile->setUserId($nuser->getUserId()); $profile->save(); $us = new DB_UserSettings(); $us->setUserId($nuser->getUserId()); $us->save(); // profile page $c = new Criteria(); $c->add("unix_name", "profiles"); $nsite = DB_SitePeer::instance()->selectOne($c); $ncategory = DB_CategoryPeer::instance()->selectByName('profile', $nsite->getSiteId()); $dup = new Duplicator(); $dup->setOwner($nuser); $dup->duplicatePage(DB_PagePeer::instance()->selectByName($nsite->getSiteId(), 'template:profile'), $nsite, $ncategory, 'profile:' . $nuser->getUnixName()); $page = DB_PagePeer::instance()->selectByName($nsite->getSiteId(), 'profile:' . $nuser->getUnixName()); $ou = new Outdater(); $ou->pageEvent('new_page', $page); $db->commit(); /* Handle originalUrl. */ $originalUrl = $runData->sessionGet('loginOriginalUrl'); if ($originalUrl) { $runData->ajaxResponseAdd('originalUrl', $originalUrl); if ($runData->sessionGet('loginOriginalUrlForce')) { $runData->ajaxResponseAdd('originalUrlForce', true); } } // reset session etc. $runData->resetSession(); $runData->getSession()->setUserId($nuser->getUserId()); setcookie("welcome", $nuser->getUserId(), time() + 10000000, "/", GlobalProperties::$SESSION_COOKIE_DOMAIN); setcookie(GlobalProperties::$SESSION_COOKIE_NAME_IE, $runData->getSessionId(), null, "/"); }
protected function appendNamespace(Duplicator $duplicator, array $namespace = NULL) { $document = $duplicator->ownerDocument; if (is_null($namespace)) { $item = $duplicator->createTemplate(__('Namespace')); } else { $item = $duplicator->createInstance(__('Namespace')); } $group = $document->createElement('div'); $group->setAttribute('class', 'group double'); // Name $label = Widget::Label(__('Name')); $input = Widget::Input('fields[namespaces][name][]', $namespace['name']); if (!is_null($namespace) && isset($namespace['name'])) { $input->setAttribute("value", $namespace['name']); } $label->appendChild($input); $group->appendChild($label); // URI $label = Widget::Label(__('URI')); $input = Widget::Input('fields[namespaces][uri][]'); if (!is_null($namespace) && isset($namespace['uri'])) { $input->setAttribute("value", $namespace['uri']); } $label->appendChild($input); $group->appendChild($label); $item->appendChild($group); }
public function cloneSiteEvent($runData) { $pl = $runData->getParameterList(); $site = $runData->getTemp("site"); $siteId = $site->getSiteId(); WDPermissionManager::instance()->canBecomeAdmin($runData->getUser()); $name = trim($pl->getParameterValue("name")); $unixName = trim($pl->getParameterValue("unixname")); $tagline = trim($pl->getParameterValue("tagline")); $description = trim($pl->getParameterValue("description")); $private = (bool) $pl->getParameterValue("private"); // validate form data: $errors = array(); if (strlen($name) < 1) { $errors['name'] = _("Site name must be present."); } elseif (strlen8($name) > 30) { $errors['name'] = _("Site name should not be longer than 30 characters."); } // site unix name ************* if ($unixName === null || strlen($unixName) < 3) { $errors['unixname'] = _("Web address must be present and should be at least 3 characters long."); } elseif (strlen($unixName) > 30) { $errors['unixname'] = _("Web address name should not be longer than 30 characters."); } elseif (preg_match("/^[a-z0-9\\-]+\$/", $unixName) == 0) { $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address.'); } elseif (preg_match("/\\-\\-/", $unixName) !== 0) { $errors['unixname'] = _('Only lowercase alphanumeric and "-" (dash) characters allowed in the web address. Double-dash (--) is not allowed.'); } else { $unixName = WDStringUtils::toUnixName($unixName); if (!$runData->getUser()->getSuperAdmin()) { // handle forbidden names $forbiddenUnixNames = explode("\n", file_get_contents(WIKIDOT_ROOT . '/conf/forbidden_site_names.conf')); foreach ($forbiddenUnixNames as $f) { if (preg_match($f, $unixName) > 0) { $errors['unixname'] = _('For some reason this web address is not allowed or is reserved for future use.'); } } } // check if the domain is not taken. $c = new Criteria(); $c->add("unix_name", $unixName); $ss = DB_SitePeer::instance()->selectOne($c); if ($ss) { $errors['unixname'] = _('Sorry, this web address is already used by another site.'); } } if (strlen8($tagline) > 50) { $errors['tagline'] = _("Tagline should not be longer than 50 characters"); } if (count($errors) > 0) { $runData->ajaxResponseAdd("formErrors", $errors); throw new ProcessException("Form errors", "form_errors"); } // and now... CREATE THE SITE!!!!!!!!!!!!!!!! $siteProps = array('name' => $name, 'subtitle' => $tagline, 'unixname' => $unixName, 'description' => $description, 'private' => $private); $dup = new Duplicator(); $dup->cloneSite($site, $siteProps); }