コード例 #1
0
 /**
  * @param FileList $list
  * @param $request
  */
 public function filterList(ItemList $list)
 {
     $owner = $this->data['owner'];
     $ui = \UserInfo::getByUserName($owner);
     if (is_object($ui)) {
         $list->filterByUserID($ui->getUserID());
     } else {
         $list->filterByUserID(-1);
     }
 }
コード例 #2
0
ファイル: wp.php プロジェクト: pranastae/problog_importer
 public function setAuthor($p)
 {
     $ak = CollectionAttributeKey::getByHandle('blog_author');
     if ($this->wp_post->author) {
         Loader::model('userinfo');
         $ui = UserInfo::getByUserName($this->wp_post->author);
         if (is_object($ui)) {
             $p->setAttribute($ak, $ui->getUserID());
         }
     }
 }
コード例 #3
0
ファイル: search.php プロジェクト: ojalehto/concrete5-legacy
 public function getRequestedSearchResults()
 {
     $dh = Loader::helper('concrete/dashboard/sitemap');
     if (!$dh->canRead()) {
         return false;
     }
     $pageList = new PageList();
     $pageList->ignoreAliases();
     $pageList->enableStickySearchRequest();
     if ($_REQUEST['submit_search']) {
         $pageList->resetSearchRequest();
     }
     $req = $pageList->getSearchRequest();
     $pageList->displayUnapprovedPages();
     $columns = PageSearchColumnSet::getCurrent();
     $this->set('columns', $columns);
     $cvName = h($req['cvName']);
     if ($cvName != '') {
         $pageList->filterByName($cvName);
     }
     if ($req['numResults'] && Loader::helper('validation/numbers')->integer($req['numResults'])) {
         $pageList->setItemsPerPage($req['numResults']);
     }
     if ($req['ctID']) {
         $pageList->filterByCollectionTypeID($req['ctID']);
     }
     if (is_array($req['selectedSearchField'])) {
         foreach ($req['selectedSearchField'] as $i => $item) {
             // due to the way the form is setup, index will always be one more than the arrays
             if ($item != '') {
                 switch ($item) {
                     case 'keywords':
                         $keywords = htmlentities($req['keywords'], ENT_QUOTES, APP_CHARSET);
                         $pageList->filterByKeywords($keywords);
                         break;
                     case 'num_children':
                         $symbol = '=';
                         if ($req['cChildrenSelect'] == 'gt') {
                             $symbol = '>';
                         } else {
                             if ($req['cChildrenSelect'] == 'lt') {
                                 $symbol = '<';
                             }
                         }
                         $pageList->filterByNumberOfChildren($req['cChildren'], $symbol);
                         break;
                     case 'owner':
                         $ui = UserInfo::getByUserName($req['owner']);
                         if (is_object($ui)) {
                             $pageList->filterByUserID($ui->getUserID());
                         } else {
                             $pageList->filterByUserID(-1);
                         }
                         break;
                     case 'theme':
                         $pageList->filter('ptID', $_REQUEST['ptID']);
                         break;
                     case 'parent':
                         if (isset($req['_cParentAll'])) {
                             $req['cParentAll'] = $req['_cParentAll'];
                         }
                         if ($req['cParentIDSearchField'] > 0) {
                             if ($req['cParentAll'] == 1) {
                                 $pc = Page::getByID($req['cParentIDSearchField']);
                                 $cPath = $pc->getCollectionPath();
                                 $pageList->filterByPath($cPath);
                             } else {
                                 $pageList->filterByParentID($req['cParentIDSearchField']);
                             }
                         }
                         break;
                     case 'version_status':
                         if (isset($req['_cvIsApproved'])) {
                             $req['cvIsApproved'] = $req['_cvIsApproved'];
                         }
                         $pageList->filterByIsApproved($req['cvIsApproved']);
                         break;
                     case 'permissions_inheritance':
                         $pageList->filter('cInheritPermissionsFrom', $req['cInheritPermissionsFrom']);
                         break;
                     case "date_public":
                         $dateFrom = $req['date_public_from'];
                         $dateTo = $req['date_public_to'];
                         if ($dateFrom != '') {
                             $dateFrom = date('Y-m-d', strtotime($dateFrom));
                             $pageList->filterByPublicDate($dateFrom, '>=');
                             $dateFrom .= ' 00:00:00';
                         }
                         if ($dateTo != '') {
                             $dateTo = date('Y-m-d', strtotime($dateTo));
                             $dateTo .= ' 23:59:59';
                             $pageList->filterByPublicDate($dateTo, '<=');
                         }
                         break;
                     case "last_modified":
                         $dateFrom = $req['last_modified_from'];
                         $dateTo = $req['last_modified_to'];
                         if ($dateFrom != '') {
                             $dateFrom = date('Y-m-d', strtotime($dateFrom));
                             $pageList->filterByDateLastModified($dateFrom, '>=');
                             $dateFrom .= ' 00:00:00';
                         }
                         if ($dateTo != '') {
                             $dateTo = date('Y-m-d', strtotime($dateTo));
                             $dateTo .= ' 23:59:59';
                             $pageList->filterByDateLastModified($dateTo, '<=');
                         }
                         break;
                     case "date_added":
                         $dateFrom = $req['date_added_from'];
                         $dateTo = $req['date_added_to'];
                         if ($dateFrom != '') {
                             $dateFrom = date('Y-m-d', strtotime($dateFrom));
                             $pageList->filterByDateAdded($dateFrom, '>=');
                             $dateFrom .= ' 00:00:00';
                         }
                         if ($dateTo != '') {
                             $dateTo = date('Y-m-d', strtotime($dateTo));
                             $dateTo .= ' 23:59:59';
                             $pageList->filterByDateAdded($dateTo, '<=');
                         }
                         break;
                     default:
                         Loader::model('attribute/categories/collection');
                         $akID = $item;
                         $fak = CollectionAttributeKey::get($akID);
                         if (!is_object($fak) || !$fak instanceof CollectionAttributeKey) {
                             break;
                         }
                         $type = $fak->getAttributeType();
                         $cnt = $type->getController();
                         $cnt->setRequestArray($req);
                         $cnt->setAttributeKey($fak);
                         $cnt->searchForm($pageList);
                         break;
                 }
             }
         }
     }
     $this->set('searchRequest', $req);
     return $pageList;
 }
コード例 #4
0
 protected function createUser()
 {
     // Make sure that this extractor supports everything we need.
     if (!$this->supportsEmail() && $this->supportsUniqueId()) {
         throw new Exception('Email and unique ID support are required for user creation.');
     }
     // Make sure that email is verified if the extractor supports it.
     if ($this->supportsVerifiedEmail() && !$this->isEmailVerified()) {
         throw new Exception('Please verify your email with this service before attempting to log in.');
     }
     $email = $this->getEmail();
     if (\UserInfo::getByEmail($email)) {
         throw new Exception('Email is already in use.');
     }
     $first_name = "";
     $last_name = "";
     $name_support = array('full' => $this->supportsFullName(), 'first' => $this->supportsFirstName(), 'last' => $this->supportsLastName());
     if ($name_support['first'] && $name_support['last']) {
         $first_name = $this->getFirstName();
         $last_name = $this->getLastName();
     } elseif ($name_support['full']) {
         $reversed_full_name = strrev($this->getFullName());
         list($reversed_last_name, $reversed_first_name) = explode(' ', $reversed_full_name, 2);
         $first_name = strrev($reversed_first_name);
         $last_name = strrev($reversed_last_name);
     }
     $username = null;
     if ($this->supportsUsername()) {
         $username = $this->getUsername();
     }
     if ($username === null) {
         if ($first_name || $last_name) {
             $username = preg_replace('/[^a-z0-9\\_]/', '_', strtolower($first_name . ' ' . $last_name));
             $username = trim(preg_replace('/_{2,}/', '_', $username), '_');
         } else {
             $username = preg_replace('/[^a-zA-Z0-9\\_]/i', '_', strtolower(substr($email, 0, strpos($email, '@'))));
             $username = trim(preg_replace('/_{2,}/', '_', $username), '_');
         }
     }
     $unique_username = $username;
     $append = 1;
     while (\UserInfo::getByUserName($unique_username)) {
         // This is a heavy handed way to do this, but it must be done.
         $unique_username = $username . '_' . $append++;
     }
     $username = $unique_username;
     $data = array();
     $data['uName'] = $username;
     $data['uPassword'] = "";
     $data['uEmail'] = $email;
     $data['uIsValidated'] = 1;
     $user_info = \UserInfo::add($data);
     if (!$user_info) {
         throw new Exception('Unable to create new account.');
     }
     if ($group_id = intval($this->registrationGroupID(), 10)) {
         $group = \Group::getByID($group_id);
         if ($group && is_object($group) && !$group->isError()) {
             $user = \User::getByUserID($user_info->getUserID());
             $user->enterGroup($group);
         }
     }
     $key = \UserAttributeKey::getByHandle('first_name');
     if ($key) {
         $user_info->setAttribute($key, $first_name);
     }
     $key = \UserAttributeKey::getByHandle('last_name');
     if ($key) {
         $user_info->setAttribute($key, $last_name);
     }
     \User::loginByUserID($user_info->getUserID());
     $this->bindUser($user = \User::getByUserID($user_info->getUserID()), $this->getUniqueId());
     return $user;
 }
コード例 #5
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
$c = Page::getByID($_REQUEST['cID'], 'RECENT');
//,"ACTIVE"
$cp = new Permissions($c);
if ($cp->canPreviewPageAsUser() && PERMISSIONS_MODEL == 'advanced') {
    $v = View::getInstance();
    $v->disableEditing();
    $v->disableLinks();
    $req = Request::get();
    $req->setCustomRequestUser(false);
    if (isset($_REQUEST['customUser'])) {
        $ui = UserInfo::getByUserName($_REQUEST['customUser']);
        if (is_object($ui)) {
            $req->setCustomRequestUser($ui->getUserObject());
        }
    }
    $dt = Loader::helper('form/date_time');
    $date = $dt->translate('onDate', $_REQUEST);
    $req->setCustomRequestDateTime($date);
    $req = Request::get();
    $cp = new Permissions($c);
    if ($cp->canRead()) {
        $v->render($c);
    } else {
        print t('Unable to view page.');
    }
}
コード例 #6
0
ファイル: pages.php プロジェクト: robertdamoc/concrete5
 public function search()
 {
     $dh = Loader::helper('concrete/dashboard/sitemap');
     if (!$dh->canRead()) {
         return false;
     }
     if ($_REQUEST['submitSearch']) {
         $this->searchRequest->resetSearchRequest();
     }
     $req = $this->searchRequest->getSearchRequest();
     $columns = PageSearchColumnSet::getCurrent();
     if (!$this->pageList->getActiveSortColumn()) {
         $col = $columns->getDefaultSortColumn();
         $this->pageList->sanitizedSortBy($col->getColumnKey(), $col->getColumnDefaultSortDirection());
     }
     $cvName = htmlentities($req['cvName'], ENT_QUOTES, APP_CHARSET);
     $this->pageList->setPageVersionToRetrieve(\Concrete\Core\Page\PageList::PAGE_VERSION_RECENT);
     if ($cvName != '') {
         $this->pageList->filterByName($cvName);
     }
     if ($req['numResults'] && Loader::helper('validation/numbers')->integer($req['numResults'])) {
         $this->pageList->setItemsPerPage($req['numResults']);
     }
     if ($req['ptID']) {
         $this->pageList->filterByPageTypeID($req['ptID']);
     }
     if (is_array($req['field'])) {
         foreach ($req['field'] as $i => $item) {
             $this->fields[] = $this->getField($item);
             // due to the way the form is setup, index will always be one more than the arrays
             if ($item != '') {
                 switch ($item) {
                     case 'keywords':
                         $keywords = htmlentities($req['keywords'], ENT_QUOTES, APP_CHARSET);
                         $this->pageList->filterByFulltextKeywords($keywords);
                         break;
                     case 'num_children':
                         $symbol = '=';
                         if ($req['cChildrenSelect'] == 'gt') {
                             $symbol = '>';
                         } elseif ($req['cChildrenSelect'] == 'lt') {
                             $symbol = '<';
                         }
                         $this->pageList->filterByNumberOfChildren($req['cChildren'], $symbol);
                         break;
                     case 'owner':
                         $ui = \UserInfo::getByUserName($req['owner']);
                         if (is_object($ui)) {
                             $this->pageList->filterByUserID($ui->getUserID());
                         } else {
                             $this->pageList->filterByUserID(-1);
                         }
                         break;
                     case 'theme':
                         $this->pageList->filter('pThemeID', $req['pThemeID']);
                         break;
                     case 'parent':
                         if (isset($req['_cParentAll'])) {
                             $req['cParentAll'] = $req['_cParentAll'];
                         }
                         if ($req['cParentIDSearchField'] > 0) {
                             if ($req['cParentAll'] == 1) {
                                 $pc = \Page::getByID($req['cParentIDSearchField']);
                                 $cPath = $pc->getCollectionPath();
                                 $this->pageList->filterByPath($cPath);
                             } else {
                                 $this->pageList->filterByParentID($req['cParentIDSearchField']);
                             }
                         }
                         break;
                     case 'version_status':
                         if (in_array($req['versionToRetrieve'], array(\Concrete\Core\Page\PageList::PAGE_VERSION_RECENT, \Concrete\Core\Page\PageList::PAGE_VERSION_ACTIVE))) {
                             $this->pageList->setPageVersionToRetrieve($req['versionToRetrieve']);
                         }
                         break;
                     case 'permissions_inheritance':
                         $this->pageList->filter('cInheritPermissionsFrom', $req['cInheritPermissionsFrom']);
                         break;
                     case "date_public":
                         $wdt = Loader::helper('form/date_time');
                         /* @var $wdt \Concrete\Core\Form\Service\Widget\DateTime */
                         $dateFrom = $wdt->translate('date_public_from', $req);
                         if ($dateFrom) {
                             $this->pageList->filterByPublicDate($dateFrom, '>=');
                         }
                         $dateTo = $wdt->translate('date_public_to', $req);
                         if ($dateTo != '') {
                             if (preg_match('/^(.+\\d+:\\d+):00$/', $dateTo, $m)) {
                                 $dateTo = $m[1] . ':59';
                             }
                             $this->pageList->filterByPublicDate($dateTo, '<=');
                         }
                         break;
                     case "last_modified":
                         $wdt = Loader::helper('form/date_time');
                         /* @var $wdt \Concrete\Core\Form\Service\Widget\DateTime */
                         $dateFrom = $wdt->translate('last_modified_from', $req);
                         if ($dateFrom) {
                             $this->pageList->filterByDateLastModified($dateFrom, '>=');
                         }
                         $dateTo = $wdt->translate('last_modified_to', $req);
                         if ($dateTo) {
                             if (preg_match('/^(.+\\d+:\\d+):00$/', $dateTo, $m)) {
                                 $dateTo = $m[1] . ':59';
                             }
                             $this->pageList->filterByDateLastModified($dateTo, '<=');
                         }
                         break;
                     case "date_added":
                         $wdt = Loader::helper('form/date_time');
                         /* @var $wdt \Concrete\Core\Form\Service\Widget\DateTime */
                         $dateFrom = $wdt->translate('date_added_from', $req);
                         if ($dateFrom) {
                             $this->pageList->filterByDateAdded($dateFrom, '>=');
                         }
                         $dateTo = $wdt->translate('date_added_to', $req);
                         if ($dateTo) {
                             if (preg_match('/^(.+\\d+:\\d+):00$/', $dateTo, $m)) {
                                 $dateTo = $m[1] . ':59';
                             }
                             $this->pageList->filterByDateAdded($dateTo, '<=');
                         }
                         break;
                     default:
                         $akID = $item;
                         $fak = CollectionAttributeKey::getByID($akID);
                         if (!is_object($fak) || !$fak instanceof CollectionAttributeKey) {
                             break;
                         }
                         $type = $fak->getAttributeType();
                         $cnt = $type->getController();
                         $cnt->setRequestArray($req);
                         $cnt->setAttributeKey($fak);
                         $cnt->searchForm($this->pageList);
                         break;
                 }
             }
         }
     }
     $ilr = new PageSearchResult($columns, $this->pageList, URL::to('/ccm/system/search/pages/submit'), $this->fields);
     $this->result = $ilr;
 }
コード例 #7
0
//causes dispatcher to skip the page rendering
define('C5_ENVIRONMENT_ONLY', true);
//prevents dispatcher from causing redirection to the base_url
define('REDIRECT_TO_BASE_URL', false);
//let's enable timezones
define('ENABLE_USER_TIMEZONES', true);
//since we can't define/redefine this for individual tests, we set to a value that's most likely to cause errors (vs '')
define('DIR_REL', '/blog');
// Force tests to start in en_US
define('SITE_LOCALE', 'en_US');
define('ACTIVE_LOCALE', 'en_US');
//this is where the magic happens
require DIR_BASE . '/concrete/dispatcher.php';
//add a user with Europe/Rome timezone
$uTest = UserInfo::getByUserName('testuser_it');
if (!is_object($uTest)) {
    $uTest = UserInfo::add(array('uName' => 'testuser_it', 'uEmail' => '*****@*****.**', 'uPassword' => 'testpassword'));
}
$uTest->update(array('uTimezone' => 'Europe/Rome'));
define('TESTUSER_IT_ID', $uTest->getUserID());
$uTest = UserInfo::getByUserName('testuser_jp');
if (!is_object($uTest)) {
    $uTest = UserInfo::add(array('uName' => 'testuser_jp', 'uEmail' => '*****@*****.**', 'uPassword' => 'testpassword'));
}
$uTest->update(array('uTimezone' => 'Asia/Tokyo'));
define('TESTUSER_JP_ID', $uTest->getUserID());
// login the admin
User::getByUserID(USER_SUPER_ID, true);
Log::addEntry('bootsrapped', 'unit tests');
// include adodb-lib to avoid a PHPUnit problem with globals
include ADODB_DIR . '/adodb-lib.inc.php';
コード例 #8
0
ファイル: pubkey.php プロジェクト: jasny/php-pubkey
 /**
  * Set specified user a logged in user.
  * 
  * @param string $user
  */
 protected function setUser($user)
 {
     if (ctype_digit($user)) {
         $uid = $user;
     } else {
         $ui = UserInfo::getByUserName($user);
         if (empty($ui)) {
             throw new Exception(sprintf(t("Unable to use pubkey: User '%s' does not exist"), $user));
         }
         $uid = $ui->getUserId();
     }
     $u = User::loginByUserID($uid);
     $loginData['success'] = 1;
     $loginData['msg'] = t('Login Successful');
     $loginData['uID'] = intval($u->getUserID());
     $loginData = $this->finishLogin($loginData);
     return $loginData;
 }
コード例 #9
0
 protected function importPageStructure(SimpleXMLElement $sx)
 {
     if (isset($sx->pages)) {
         $nodes = array();
         $i = 0;
         foreach ($sx->pages->page as $p) {
             $p->originalPos = $i;
             $nodes[] = $p;
             $i++;
         }
         usort($nodes, array('ContentImporter', 'setupPageNodeOrder'));
         $home = Page::getByID(HOME_CID, 'RECENT');
         foreach ($nodes as $px) {
             $pkg = ContentImporter::getPackageObject($px['package']);
             $data = array();
             $user = (string) $px['user'];
             if ($user != '') {
                 $ui = UserInfo::getByUserName($user);
                 if (is_object($ui)) {
                     $data['uID'] = $ui->getUserID();
                 } else {
                     $data['uID'] = USER_SUPER_ID;
                 }
             }
             $cDatePublic = (string) $px['public-date'];
             if ($cDatePublic) {
                 $data['cDatePublic'] = $cDatePublic;
             }
             $data['pkgID'] = 0;
             if (is_object($pkg)) {
                 $data['pkgID'] = $pkg->getPackageID();
             }
             $args = array();
             $ct = CollectionType::getByHandle($px['pagetype']);
             if ($px['path'] == '') {
                 // home page
                 $page = $home;
                 $args['ctID'] = $ct->getCollectionTypeID();
             } else {
                 $page = Page::getByPath($px['path']);
                 if (!is_object($page) || $page->isError()) {
                     $lastSlash = strrpos((string) $px['path'], '/');
                     $parentPath = substr((string) $px['path'], 0, $lastSlash);
                     $data['cHandle'] = substr((string) $px['path'], $lastSlash + 1);
                     if (!$parentPath) {
                         $parent = $home;
                     } else {
                         $parent = Page::getByPath($parentPath);
                     }
                     $page = $parent->add($ct, $data);
                 }
             }
             $args['cName'] = $px['name'];
             $args['cDescription'] = $px['description'];
             $args['ctID'] = $ct->getCollectionTypeID();
             $page->update($args);
         }
     }
 }
コード例 #10
0
 function addWordpressPage(Page $p, CollectionType $ct, PageLite $pl, $xmlID)
 {
     /*		echo $pl->getPostdate();
     		exit;
     		*/
     $u = new User();
     $pageAuthor = $pl->getAuthor();
     $ui = UserInfo::getByUserName($pageAuthor);
     if (is_object($ui)) {
         $uID = $ui->getUserID();
     } else {
         $uID = $u->getUserID();
     }
     $pageData = array('cName' => $pl->getTitle(), 'cDatePublic' => $pl->getPostdate(), 'cDateAdded' => $pl->getPostdate(), 'cDescription' => $pl->getExcerpt(), 'uID' => $uID);
     $newPage = $p->add($ct, $pageData);
     if (is_array($pl->getCategory())) {
         $newPage->setAttribute('wordpress_category', $pl->getCategory());
     }
     if (is_array($pl->getTags())) {
         $newPage->setAttribute('tags', $pl->getTags());
     }
     if (count($pl->getComments()) > 0) {
         $blocks = $newPage->getBlocks("Blog Post Footer");
         $haveGuestbook = 0;
         foreach ($blocks as $block) {
             if ($block->getBlockTypeHandle() == "guestbook") {
                 $bID = $block->getBlockID();
                 $haveGuestbook = 1;
             }
         }
         if ($haveGuestbook == 0) {
             $data = array();
             $data['title'] = "Comments:";
             $data['dateFormat'] = "M jS, Y";
             $data['requireApproval'] = 0;
             $data['displayGuestBookForm'] = 1;
             $data['authenticationRequired'] = 0;
             $data['displayCaptcha'] = 1;
             $bt = BlockType::getByHandle("guestbook");
             $guestbook = $newPage->addBlock($bt, "Blog Post Footer", $data);
             $bID = $guestbook->getBlockID();
         }
         Loader::model('comment_lite', 'wordpress_site_importer');
         $comments = $pl->getComments();
         foreach ($comments as $comment) {
             if (!$comment['comment_type'] == "pingback") {
                 CommentLite::addcomment($bID, $comment['commentText'], $comment['name'], $comment['email'], $comment['approved'], $newPage->getCollectionID(), 0, $comment['comment_date']);
             }
         }
     }
     $blocks = $newPage->getBlocks("Main");
     foreach ($blocks as $block) {
         $block->delete();
     }
     $blocks = $newPage->getBlocks("Blog Post More");
     foreach ($blocks as $block) {
         $block->delete();
     }
     Loader::model('block_types');
     $bt = BlockType::getByHandle('content');
     $data = array();
     $data['content'] = $this->importImages ? $this->determineImportableMediaFromContent($pl->getContent(), $pageData) : $pl->getContent();
     //we're either importing images or not
     $newPage->addBlock($bt, "Main", $data);
     $db = Loader::db();
     $q = 'UPDATE WordpressItems SET cID = ?, wpID = ?, wpParentID = ?, wpPostType = ? WHERE id=?';
     $v = array($newPage->getCollectionID(), $pl->getPostID(), $pl->getWpParentID(), $pl->getPostType(), $xmlID);
     $res = $db->query($q, $v);
     return $newPage;
 }