Example #1
2
 public function saveEntryAttributesForm(Form $form, Entry $entry)
 {
     foreach ($form->getControls() as $control) {
         $type = $control->getControlType();
         $saver = $type->getSaveHandler($control);
         if ($saver instanceof SaveHandlerInterface) {
             $saver->saveFromRequest($control, $entry, $this->request);
         }
     }
     $this->entityManager->flush();
     $ev = new Event($entry);
     $ev->setEntityManager($this->entityManager);
     \Events::dispatch('on_express_entry_saved', $ev);
     return $ev->getEntry();
 }
Example #2
0
 /**
  * @todo Implement testFire().
  */
 public function testFire()
 {
     $observer = new EventsTestObserver();
     $this->object->addListener('fire', array($observer, 'invoke'));
     $event = new GenericEvent('dontfire', array('a' => 1, 'b' => 2));
     $this->object->dispatch('dontfire');
     $this->assertEquals(0, $observer->invoked);
     $event = new GenericEvent('fire', array('a' => 18, 'b' => 81));
     $this->object->dispatch('fire', $event);
     $this->assertEquals(1, $observer->invoked);
     $this->assertEquals('81', $observer->event['b']);
 }
 public function saveForm(Page $c)
 {
     $controls = Control::getList($this->type);
     $outputControls = array();
     foreach ($controls as $cn) {
         $data = $cn->getRequestValue();
         $cn->publishToPage($c, $data, $controls);
         $outputControls[] = $cn;
     }
     // set page name from controls
     // now we see if there's a page name field in there
     $containsPageNameControl = false;
     foreach ($outputControls as $cn) {
         if ($cn instanceof NameCorePageProperty) {
             $containsPageNameControl = true;
             break;
         }
     }
     if (!$containsPageNameControl) {
         foreach ($outputControls as $cn) {
             if ($cn->canPageTypeComposerControlSetPageName()) {
                 $pageName = $cn->getPageTypeComposerControlPageNameValue($c);
                 $c->updateCollectionName($pageName);
             }
         }
     }
     // remove all but the most recent X drafts.
     if ($c->isPageDraft()) {
         $vl = new VersionList($c);
         $vl->setItemsPerPage(-1);
         // this will ensure that we only ever keep X versions.
         $vArray = $vl->getPage();
         if (count($vArray) > $this->ptDraftVersionsToSave) {
             for ($i = $this->ptDraftVersionsToSave; $i < count($vArray); ++$i) {
                 $v = $vArray[$i];
                 @$v->delete();
             }
         }
     }
     $c = Page::getByID($c->getCollectionID(), 'RECENT');
     $controls = array();
     foreach ($outputControls as $oc) {
         $oc->setPageObject($c);
         $controls[] = $oc;
     }
     $ev = new Event($c);
     $ev->setPageType($this->type);
     $ev->setArgument('controls', $controls);
     \Events::dispatch('on_page_type_save_composer_form', $ev);
     return $controls;
 }
Example #4
0
 protected function notifyAdmin($offenderID)
 {
     $offender = UserInfo::getByID($offenderID);
     $ue = new \Concrete\Core\User\Event\UserInfo($offender);
     Events::dispatch('on_private_message_over_limit', $ue);
     $admin = UserInfo::getByID(USER_SUPER_ID);
     Log::addEntry(t("User: %s has tried to send more than %s private messages within %s minutes", $offender->getUserName(), \Config::get('concrete.user.private_messages.throttle_max'), \Config::get('concrete.user.private_messages.throttle_max_timespan')), t('warning'));
     Loader::helper('mail');
     $mh = new MailHelper();
     $mh->addParameter('offenderUname', $offender->getUserName());
     $mh->addParameter('profileURL', BASE_URL . View::url('/profile', 'view', $offender->getUserID()));
     $mh->addParameter('profilePreferencesURL', BASE_URL . View::url('/profile/edit'));
     $mh->to($admin->getUserEmail());
     $mh->load('private_message_admin_warning');
     $mh->sendMail();
 }
Example #5
0
 public function submit()
 {
     if ($this->validateAction()) {
         if ($this->permissions->canDeleteBlock()) {
             $b = $this->getBlockToEdit();
             $pr = $this->getEditResponse($b);
             // Since we have the OLD block ID in the DOM, we need to override that bID
             $pr->setAdditionalDataAttribute('bID', $this->block->getBlockID());
             $b->deleteBlock();
             $event = new BlockDelete($b, $this->page);
             \Events::dispatch('on_block_delete', $event);
             $b->getBlockCollectionObject()->rescanDisplayOrder($_REQUEST['arHandle']);
             $pr->setMessage(t('Block deleted successfully.'));
             $pr->outputJSON();
         }
     }
 }
Example #6
0
 /**
  * Utility method for clearing all application caches.
  */
 public function clearCaches()
 {
     \Events::dispatch('on_cache_flush');
     Core::make('cache')->flush();
     Core::make('cache/expensive')->flush();
     // flush the CSS cache
     if (is_dir(DIR_FILES_CACHE . '/' . DIRNAME_CSS)) {
         $fh = Loader::helper("file");
         $fh->removeAll(DIR_FILES_CACHE . '/' . DIRNAME_CSS);
     }
     $pageCache = PageCache::getLibrary();
     if (is_object($pageCache)) {
         $pageCache->flush();
     }
     // clear the environment overrides cache
     $env = \Environment::get();
     $env->clearOverrideCache();
     // Clear localization cache
     Localization::clearCache();
     // clear block type cache
     BlockType::clearCache();
 }
 public function delete()
 {
     $db = Loader::db();
     if (!$this->uID) {
         return false;
     }
     $ue = new Event($this);
     $ue = Events::dispatch('on_private_message_delete', $ue);
     if (!$ue) {
         return;
     }
     $db->Execute('delete from UserPrivateMessagesTo where uID = ? and msgID = ?', array($this->uID, $this->msgID));
 }
Example #8
0
 public function getOutput($request = null)
 {
     $pl = $this->getPageListObject();
     if ($this->cParentID) {
         $parent = Page::getByID($this->cParentID);
         $link = $parent->getCollectionLink();
     }
     $pagination = $pl->getPagination();
     if ($pagination->getTotalResults() > 0) {
         $writer = new \Zend\Feed\Writer\Feed();
         $writer->setTitle($this->getTitle());
         $writer->setDescription($this->getDescription());
         $writer->setLink((string) $link);
         foreach ($pagination->getCurrentPageResults() as $p) {
             $entry = $writer->createEntry();
             $entry->setTitle($p->getCollectionName());
             $entry->setDateCreated(strtotime($p->getCollectionDatePublic()));
             $content = $this->getPageFeedContent($p);
             if (!$content) {
                 $content = t('No Content.');
             }
             $entry->setDescription($content);
             $entry->setLink((string) $p->getCollectionLink(true));
             $writer->addEntry($entry);
         }
         $ev = new FeedEvent($parent);
         $ev->setFeedObject($this);
         $ev->setWriterObject($writer);
         $ev->setRequest($request);
         $ev = \Events::dispatch('on_page_feed_output', $ev);
         $writer = $ev->getWriterObject();
         return $writer->export('rss');
     }
 }
Example #9
0
 /**
  * Utility method for clearing all application caches.
  */
 public function clearCaches()
 {
     \Events::dispatch('on_cache_flush');
     $this['cache']->flush();
     $this['cache/expensive']->flush();
     $config = $this['config'];
     // Delete and re-create the cache directory
     $cacheDir = $config->get('concrete.cache.directory');
     if (is_dir($cacheDir)) {
         $fh = Core::make('helper/file');
         $fh->removeAll($cacheDir, true);
     }
     $this->setupFilesystem();
     $pageCache = PageCache::getLibrary();
     if (is_object($pageCache)) {
         $pageCache->flush();
     }
     // clear the environment overrides cache
     $env = \Environment::get();
     $env->clearOverrideCache();
     // Clear localization cache
     Localization::clearCache();
     // clear block type cache
     BlockType::clearCache();
     // Clear precompiled script bytecode caches
     OpCache::clear();
 }
Example #10
0
 /**
  * Utility method for clearing all application caches.
  */
 public function clearCaches()
 {
     \Events::dispatch('on_cache_flush');
     $this['cache']->flush();
     $this['cache/expensive']->flush();
     $config = $this['config'];
     // Delete and re-create the cache directory
     $cacheDir = $config->get('concrete.cache.directory');
     if (is_dir($cacheDir)) {
         $fh = Core::make('helper/file');
         $fh->removeAll($cacheDir, true);
     }
     $this->setupFilesystem();
     $pageCache = PageCache::getLibrary();
     if (is_object($pageCache)) {
         $pageCache->flush();
     }
     // Clear the file thumbnail path cache
     $connection = $this['database'];
     $sql = $connection->getDatabasePlatform()->getTruncateTableSQL('FileImageThumbnailPaths');
     try {
         $connection->executeUpdate($sql);
     } catch (\Exception $e) {
     }
     // clear the environment overrides cache
     $env = \Environment::get();
     $env->clearOverrideCache();
     // Clear localization cache
     Localization::clearCache();
     // clear block type cache
     BlockType::clearCache();
     // Clear precompiled script bytecode caches
     OpCache::clear();
     \Events::dispatch('on_cache_flush_end');
 }
Example #11
0
<?php

$DIR_BASE_CORE = dirname(__DIR__);
define('DIR_BASE', dirname($DIR_BASE_CORE));
require $DIR_BASE_CORE . '/bootstrap/configure.php';
require $DIR_BASE_CORE . '/bootstrap/autoload.php';
if (!\Concrete\Core\Application\Application::isRunThroughCommandLineInterface()) {
    return false;
}
$cms = (require $DIR_BASE_CORE . '/bootstrap/start.php');
$app = new \Concrete\Core\Console\Application();
$cms->instance('console', $app);
if ($cms->isInstalled()) {
    $cms->setupPackageAutoloaders();
    $cms->setupPackages();
}
$app->setupDefaultCommands();
\Events::dispatch('on_before_console_run');
$app->run();
\Events::dispatch('on_after_console_run');
Example #12
0
 public function publish(Page $c, $requestOrDateTime = null)
 {
     $this->stripEmptyPageTypeComposerControls($c);
     $parent = Page::getByID($c->getPageDraftTargetParentPageID());
     if ($c->isPageDraft()) {
         // this is still a draft, which means it has never been properly published.
         // so we need to move it, check its permissions, etc...
         Section::registerPage($c);
         $c->move($parent);
         if (!$parent->overrideTemplatePermissions()) {
             // that means the permissions of pages added beneath here inherit from page type permissions
             // this is a very poorly named method. Template actually used to mean Type.
             // so this means we need to set the permissions of this current page to inherit from page types.
             $c->inheritPermissionsFromDefaults();
         }
         $c->activate();
     } else {
         $c->rescanCollectionPath();
     }
     $u = new User();
     if (!$requestOrDateTime instanceof ApprovePagePageWorkflowRequest) {
         $v = CollectionVersion::get($c, 'RECENT');
         $pkr = new ApprovePagePageWorkflowRequest();
         $pkr->setRequestedPage($c);
         $pkr->setRequestedVersionID($v->getVersionID());
         $pkr->setRequesterUserID($u->getUserID());
         if ($requestOrDateTime) {
             // That means it's a date time
             $pkr->scheduleVersion($requestOrDateTime);
         }
     } else {
         $pkr = $requestOrDateTime;
     }
     $pkr->trigger();
     $u->unloadCollectionEdit($c);
     CacheLocal::flush();
     $ev = new Event($c);
     $ev->setPageType($this);
     $ev->setUser($u);
     \Events::dispatch('on_page_type_publish', $ev);
 }
$linkTags = array();
if (($favIconFID = intval(Config::get('concrete.misc.favicon_fid'))) && ($favIconFile = File::getByID($favIconFID)) && is_object($favIconFile)) {
    $favIconFileURL = $favIconFile->getURL();
    $linkTags['shortcut icon'] = sprintf('<link rel="shortcut icon" href="%s" type="image/x-icon"/>', $favIconFileURL);
    $linkTags['icon'] = sprintf('<link rel="icon" href="%s" type="image/x-icon"/>', $favIconFileURL);
}
if (($appleIconFID = intval(Config::get('concrete.misc.iphone_home_screen_thumbnail_fid'))) && ($appleIconFile = File::getByID($appleIconFID)) && is_object($appleIconFile)) {
    $linkTags['apple-touch-icon'] = sprintf('<link rel="apple-touch-icon" href="%s"/>', $appleIconFile->getURL());
}
// Generate and dispatch an event, to let other Add-Ons make use of the available (meta) tags/page title
$event = new \Symfony\Component\EventDispatcher\GenericEvent();
$event->setArgument('metaTags', $metaTags);
$event->setArgument('linkTags', $linkTags);
$event->setArgument('pageTitle', $pageTitle);
$event->setArgument('defaultPageTitle', $defaultPageTitle);
Events::dispatch('on_header_required_ready', $event);
$metaTags = $event->getArgument('metaTags');
$linkTags = $event->getArgument('linkTags');
$pageTitle = $event->getArgument('pageTitle');
?>

<title><?php 
echo htmlspecialchars($pageTitle, ENT_COMPAT, APP_CHARSET);
?>
</title>

<?php 
echo implode(PHP_EOL, $metaTags);
if (!empty($linkTags)) {
    echo implode(PHP_EOL, $linkTags);
}
Example #14
0
                }
                $b = Block::getByID($_REQUEST['bID'], $cx, $ax);
                $p = new Permissions($b);
                // might be block-level, or it might be area level
                // we're removing a particular block of content
                if ($p->canDeleteBlock()) {
                    $nvc = $cx->getVersionToModify();
                    if ($a->isGlobalArea()) {
                        $xvc = $c->getVersionToModify();
                        // we need to create a new version of THIS page as well.
                        $xvc->relateVersionEdits($nvc);
                    }
                    $b->loadNewCollection($nvc);
                    $b->deleteBlock();
                    $event = new BlockDelete($b, $c);
                    \Events::dispatch('on_block_delete', $event);
                    $nvc->rescanDisplayOrder($_REQUEST['arHandle']);
                    if (isset($_POST['isAjax'])) {
                        exit;
                    }
                    $cID = $securityHelper->sanitizeInt($_GET['cID']);
                    header('Location: ' . \Core::getApplicationURL() . '/' . DISPATCHER_FILENAME . '?cID=' . $cID . '&mode=edit' . $step);
                    exit;
                }
            }
            break;
    }
}
if (isset($_GET['atask']) && $_GET['atask'] && $valt->validate()) {
    switch ($_GET['atask']) {
        case 'add_stack':
Example #15
0
 * methods
 * ----------------------------------------------------------------------------
 */
$cms->setupPackages();
/**
 * ----------------------------------------------------------------------------
 * Load all permission keys into our local cache.
 * ----------------------------------------------------------------------------
 */
PermissionKey::loadAll();
/**
 * ----------------------------------------------------------------------------
 * Fire an event for intercepting the dispatch
 * ----------------------------------------------------------------------------
 */
\Events::dispatch('on_before_dispatch');
/**
 * ----------------------------------------------------------------------------
 * Get the response to the current request
 * ----------------------------------------------------------------------------
 */
$response = $cms->dispatch($request);
/**
 * ----------------------------------------------------------------------------
 * Send it to the user
 * ----------------------------------------------------------------------------
 */
$response->send();
/**
 * ----------------------------------------------------------------------------
 * Return the CMS object.
 /**
  * @param array $data
  * @return UserInfo|false|null
  */
 public function create($data)
 {
     $uae = new AddUser($data);
     $uae = \Events::dispatch('on_before_user_add', $uae);
     if (!$uae->proceed()) {
         return false;
     }
     $db = $this->connection;
     $dh = $this->application->make('date');
     $uDateAdded = $dh->getOverridableNow();
     $config = $this->application->make('config');
     $hasher = new PasswordHash($config->get('concrete.user.password.hash_cost_log2'), $config->get('concrete.user.password.hash_portable'));
     if (isset($data['uIsValidated']) && $data['uIsValidated'] == 1) {
         $uIsValidated = 1;
     } elseif (isset($data['uIsValidated']) && $data['uIsValidated'] == 0) {
         $uIsValidated = 0;
     } else {
         $uIsValidated = -1;
     }
     if (isset($data['uIsFullRecord']) && $data['uIsFullRecord'] == 0) {
         $uIsFullRecord = 0;
     } else {
         $uIsFullRecord = 1;
     }
     $password_to_insert = isset($data['uPassword']) ? $data['uPassword'] : null;
     $hash = $hasher->HashPassword($password_to_insert);
     $uDefaultLanguage = null;
     if (isset($data['uDefaultLanguage']) && $data['uDefaultLanguage'] != '') {
         $uDefaultLanguage = $data['uDefaultLanguage'];
     }
     $v = array($data['uName'], $data['uEmail'], $hash, $uIsValidated, $uDateAdded, $uDateAdded, $uIsFullRecord, $uDefaultLanguage, 1);
     $r = $db->prepare("insert into Users (uName, uEmail, uPassword, uIsValidated, uDateAdded, uLastPasswordChange, uIsFullRecord, uDefaultLanguage, uIsActive) values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
     $res = $r->execute($v);
     if ($res) {
         $newUID = $db->Insert_ID();
         $ui = $this->userInfoFactory->getByID($newUID);
         if (is_object($ui)) {
             $uo = $ui->getUserObject();
             $groupControllers = \Group::getAutomatedOnRegisterGroupControllers($uo);
             foreach ($groupControllers as $ga) {
                 if ($ga->check($uo)) {
                     $uo->enterGroup($ga->getGroupObject());
                 }
             }
             // run any internal event we have for user add
             $ue = new UserInfoWithPassword($ui);
             $ue->setUserPassword($password_to_insert);
             \Events::dispatch('on_user_add', $ue);
         }
         return $ui;
     }
 }
Example #17
0
 public static function ignorePageRelation($page, $locale)
 {
     $db = Database::get();
     // first, we retrieve the relation for the page in the default locale.
     $mpRelationID = static::registerPage($page);
     $v = [$mpRelationID, 0, $locale];
     $db->Execute('insert into MultilingualPageRelations (mpRelationID, cID, mpLocale) values (?, ?, ?)', $v);
     $pde = new Event($page);
     $pde->setLocale($locale);
     \Events::dispatch('on_multilingual_page_ignore', $pde);
 }
 /**
  * @param array $data
  *
  * @return UserInfo|false|null
  */
 public function create($data)
 {
     $uae = new AddUser($data);
     $uae = \Events::dispatch('on_before_user_add', $uae);
     if (!$uae->proceed()) {
         return false;
     }
     $config = $this->application->make('config');
     $hasher = new PasswordHash($config->get('concrete.user.password.hash_cost_log2'), $config->get('concrete.user.password.hash_portable'));
     if (isset($data['uIsValidated']) && $data['uIsValidated'] == 1) {
         $uIsValidated = 1;
     } elseif (isset($data['uIsValidated']) && $data['uIsValidated'] == 0) {
         $uIsValidated = 0;
     } else {
         $uIsValidated = -1;
     }
     if (isset($data['uIsFullRecord']) && $data['uIsFullRecord'] == 0) {
         $uIsFullRecord = 0;
     } else {
         $uIsFullRecord = 1;
     }
     $password_to_insert = isset($data['uPassword']) ? $data['uPassword'] : null;
     $hash = $hasher->HashPassword($password_to_insert);
     $uDefaultLanguage = null;
     if (isset($data['uDefaultLanguage']) && $data['uDefaultLanguage'] != '') {
         $uDefaultLanguage = $data['uDefaultLanguage'];
     }
     $entity = new UserEntity();
     $entity->setUserName($data['uName']);
     $entity->setUserEmail($data['uEmail']);
     $entity->setUserPassword($hash);
     $entity->setUserIsValidated($uIsValidated);
     $entity->setUserIsFullRecord($uIsFullRecord);
     $entity->setUserDefaultLanguage($uDefaultLanguage);
     $entity->setUserIsActive(true);
     $this->entityManager->persist($entity);
     $this->entityManager->flush();
     $newUID = $entity->getUserID();
     $ui = $this->userInfoRepository->getByID($newUID);
     if (is_object($ui)) {
         $uo = $ui->getUserObject();
         $groupControllers = \Group::getAutomatedOnRegisterGroupControllers($uo);
         foreach ($groupControllers as $ga) {
             if ($ga->check($uo)) {
                 $uo->enterGroup($ga->getGroupObject());
             }
         }
         // run any internal event we have for user add
         $ue = new UserInfoWithPassword($ui);
         $ue->setUserPassword($password_to_insert);
         \Events::dispatch('on_user_add', $ue);
         // Now we notify any relevant users.
         /**
          * @var $type UserSignupType
          */
         $type = $this->application->make('manager/notification/types')->driver('user_signup');
         $u = new User();
         $createdBy = null;
         if (is_object($u)) {
             $creator = $u->getUserInfoObject();
             if (is_object($creator)) {
                 $createdBy = $creator->getEntityObject();
             }
         }
         $signup = new UserSignup($ui->getEntityObject(), $createdBy);
         $notifier = $type->getNotifier();
         $subscription = $type->getSubscription($signup);
         $notified = $notifier->getUsersToNotify($subscription, $signup);
         $notification = $type->createNotification($signup);
         $notifier->notify($notified, $notification);
     }
     return $ui;
 }