public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('title', 'text', array('label' => 'Title', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED, 'attr' => array('autofocus' => 'autofocus'))); $builder->add('slug', 'text', array('label' => 'Address', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED)); $myExtraFieldValidator = function (FormEvent $event) { global $CONFIG; $form = $event->getForm(); $myExtraField = $form->get('slug')->getData(); if (!ctype_alnum($myExtraField) || strlen($myExtraField) < 2) { $form['slug']->addError(new FormError("Numbers and letters only, at least 2.")); } else { if (in_array($myExtraField, $CONFIG->siteSlugReserved)) { $form['slug']->addError(new FormError("That is already taken.")); // The above checks provide a nice error message. // Now let's do a final belt and braces check. } else { if (!SiteModel::isSlugValid($myExtraField, $CONFIG)) { $form['slug']->addError(new FormError("That is not allowed.")); } } } }; $builder->addEventListener(FormEvents::POST_BIND, $myExtraFieldValidator); $readChoices = array('public' => 'Public, and listed on search engines and our directory', 'protected' => 'Public, but not listed so only people who know about it can find it'); $builder->add('read', 'choice', array('label' => 'Who can read?', 'required' => true, 'choices' => $readChoices, 'expanded' => true)); $builder->get('read')->setData('public'); $writeChoices = array('public' => 'Anyone can add data', 'protected' => 'Only people I say can add data'); $builder->add('write', 'choice', array('label' => 'Who can write?', 'required' => true, 'choices' => $writeChoices, 'expanded' => true)); $builder->get('write')->setData('public'); }
public function create(SiteModel $site, UserAccountModel $owner, $countries, SiteQuotaModel $siteQuota, $canAnyUserVerifiedEdit = false) { global $DB, $CONFIG, $EXTENSIONHOOKRUNNER; $createdat = \TimeSource::getFormattedForDataBase(); if (!$site->isSlugValid($site->getSlug(), $CONFIG)) { throw new Exception("Slug not valid"); } try { $DB->beginTransaction(); // TODO should check slug not already exist and nice error $timezones = array(); foreach ($countries as $country) { foreach (explode(",", $country->getTimezones()) as $timeZone) { $timezones[] = $timeZone; } } $site->setCachedTimezonesAsList($timezones); $site->setCachedIsMultipleCountries(count($countries) > 1); // Site $stat = $DB->prepare("INSERT INTO site_information (title, slug, slug_canonical, " . "created_at,cached_is_multiple_timezones,cached_is_multiple_countries," . "cached_timezones,is_feature_map,is_feature_importer,is_feature_curated_list," . "is_listed_in_index,is_web_robots_allowed, " . " prompt_emails_days_in_advance,site_quota_id, " . "is_feature_tag,is_feature_physical_events,is_feature_virtual_events) " . "VALUES (:title, :slug, :slug_canonical, " . " :created_at,:cached_is_multiple_timezones,:cached_is_multiple_countries," . ":cached_timezones,:is_feature_map,:is_feature_importer,:is_feature_curated_list," . ":is_listed_in_index,:is_web_robots_allowed, " . " :prompt_emails_days_in_advance, :site_quota_id, " . ":is_feature_tag,:is_feature_physical_events,:is_feature_virtual_events) RETURNING id"); $stat->execute(array('title' => substr($site->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'slug' => $site->getSlug(), 'slug_canonical' => SiteModel::makeCanonicalSlug($site->getSlug()), 'cached_is_multiple_timezones' => $site->getCachedIsMultipleTimezones() ? 1 : 0, 'cached_is_multiple_countries' => $site->getCachedIsMultipleCountries() ? 1 : 0, 'cached_timezones' => $site->getCachedTimezones(), 'created_at' => $createdat, 'is_feature_curated_list' => $site->getIsFeatureCuratedList() ? 1 : 0, 'is_feature_importer' => $site->getIsFeatureImporter() ? 1 : 0, 'is_feature_map' => $site->getIsFeatureMap() ? 1 : 0, 'is_feature_tag' => $site->getIsFeatureTag() ? 1 : 0, 'is_feature_virtual_events' => $site->getIsFeatureVirtualEvents() ? 1 : 0, 'is_feature_physical_events' => $site->getIsFeaturePhysicalEvents() ? 1 : 0, 'is_listed_in_index' => $site->getIsListedInIndex() ? 1 : 0, 'is_web_robots_allowed' => $site->getIsWebRobotsAllowed() ? 1 : 0, 'prompt_emails_days_in_advance' => $site->getPromptEmailsDaysInAdvance(), 'site_quota_id' => $siteQuota->getId())); $data = $stat->fetch(); $site->setId($data['id']); $stat = $DB->prepare("INSERT INTO site_history (site_id, user_account_id, " . "title, slug, slug_canonical, created_at,is_feature_map,is_feature_importer," . "is_feature_curated_list,is_listed_in_index,is_web_robots_allowed, " . " prompt_emails_days_in_advance, is_new," . "is_feature_tag,is_feature_physical_events,is_feature_virtual_events) " . "VALUES (:site_id, :user_account_id, :title, " . ":slug, :slug_canonical, :created_at,:is_feature_map,:is_feature_importer," . ":is_feature_curated_list,:is_listed_in_index,:is_web_robots_allowed, " . " :prompt_emails_days_in_advance, '1', " . ":is_feature_tag,:is_feature_physical_events,:is_feature_virtual_events)"); $stat->execute(array('site_id' => $site->getId(), 'user_account_id' => $owner->getId(), 'title' => substr($site->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED), 'slug' => $site->getSlug(), 'slug_canonical' => SiteModel::makeCanonicalSlug($site->getSlug()), 'created_at' => $createdat, 'is_feature_curated_list' => $site->getIsFeatureCuratedList() ? 1 : 0, 'is_feature_importer' => $site->getIsFeatureImporter() ? 1 : 0, 'is_feature_map' => $site->getIsFeatureMap() ? 1 : 0, 'is_feature_tag' => $site->getIsFeatureTag() ? 1 : 0, 'is_feature_virtual_events' => $site->getIsFeatureVirtualEvents() ? 1 : 0, 'is_feature_physical_events' => $site->getIsFeaturePhysicalEvents() ? 1 : 0, 'is_listed_in_index' => $site->getIsListedInIndex() ? 1 : 0, 'is_web_robots_allowed' => $site->getIsWebRobotsAllowed() ? 1 : 0, 'prompt_emails_days_in_advance' => $site->getPromptEmailsDaysInAdvance())); // Permissions $ugr = new UserGroupRepository(); $userGroupEditors = new UserGroupModel(); $userGroupEditors->setTitle("Editors"); $userGroupEditors->setIsIncludesVerifiedUsers($canAnyUserVerifiedEdit); $ugr->createForSite($site, $userGroupEditors, $owner, array(array('org.openacalendar', 'CALENDAR_CHANGE')), array($owner)); $userGroupEditors = new UserGroupModel(); $userGroupEditors->setTitle("Administrators"); $ugr->createForSite($site, $userGroupEditors, $owner, array(array('org.openacalendar', 'CALENDAR_ADMINISTRATE')), array($owner)); // Countries! $stat = $DB->prepare("INSERT INTO country_in_site_information (site_id,country_id,is_in,is_previously_in,created_at) VALUES (:site_id,:country_id,'1','1',:created_at)"); foreach ($countries as $country) { $stat->execute(array('country_id' => $country->getId(), 'site_id' => $site->getId(), 'created_at' => $createdat)); } $stat = $DB->prepare("INSERT INTO user_watches_site_information (user_account_id,site_id,is_watching,is_was_once_watching,last_watch_started,created_at) " . "VALUES (:user_account_id,:site_id,:is_watching,:is_was_once_watching,:last_watch_started,:created_at)"); $stat->execute(array('user_account_id' => $owner->getId(), 'site_id' => $site->getId(), 'is_watching' => '1', 'is_was_once_watching' => '1', 'created_at' => \TimeSource::getFormattedForDataBase(), 'last_watch_started' => \TimeSource::getFormattedForDataBase())); $DB->commit(); $EXTENSIONHOOKRUNNER->afterSiteCreate($site, $owner); } catch (Exception $e) { $DB->rollBack(); } }
/** * @dataProvider providerSlugIsNotValid */ function testSlugIsNotValid($in) { global $CONFIG; $CONFIG->siteSlugReserved = array('www'); $this->assertFalse(SiteModel::isSlugValid($in, $CONFIG)); }
* * This shouldn't really be here; but at the moment it's used by the install process. * It should be in cliapi1 and there should be a seperate explicit installer (web, cli, or both) * * @package Core * @link http://ican.openacalendar.org/ OpenACalendar Open Source Software * @license http://ican.openacalendar.org/license.html 3-clause BSD * @copyright (c) 2013-2014, JMB Technology Limited, http://jmbtechnology.co.uk/ * @author James Baster <*****@*****.**> */ $slug = $argv[1]; $email = $argv[2]; if (!$slug || !$email) { die("Slug and Email?\n\n"); } if (!SiteModel::isSlugValid($slug, $CONFIG)) { die("Slug is not valid!\n\n"); } print "Slug: " . $slug . "\n"; print "Email: " . $email . "\n"; sleep(10); print "Starting ...\n"; $userRepository = new UserAccountRepository(); $user = $userRepository->loadByUserNameOrEmail($email); if (!$user) { die("Can't load user!\n\n"); } $site = new SiteModel(); $site->setSlug($slug); $site->setTitle($slug); $site->setIsListedInIndex(true);