public static function addStack($stackName, $type = self::ST_TYPE_USER_ADDED) { $ct = new CollectionType(); $data = array(); $parent = Page::getByPath(STACKS_PAGE_PATH); $data = array(); $data['name'] = $stackName; if (!$stackName) { $data['name'] = t('No Name'); } $pagetype = CollectionType::getByHandle(STACKS_PAGE_TYPE); $page = $parent->add($pagetype, $data); // we have to do this because we need the area to exist before we try and add something to it. $a = Area::getOrCreate($page, STACKS_AREA_NAME); // finally we add the row to the stacks table $db = Loader::db(); $stackCID = $page->getCollectionID(); $v = array($stackName, $stackCID, $type); $db->Execute('insert into Stacks (stName, cID, stType) values (?, ?, ?)', $v); //Return the new stack return self::getByID($stackCID); }
public function testPageOperations() { Loader::model('page'); Loader::model('collection_types'); $ct = CollectionType::getByHandle('left_sidebar'); //everything's got a default.. $this->assertInstanceOf('CollectionType', $ct); //kind of weird to check this but hey $home = Page::getByID(HOME_CID); $pageName = "My Cool Page"; $pageHandle = 'page'; //this tests that page handles will be set as the page handle. //The actual add function does some transforms on the handles if they are not //set. $badPage = Page::getByID(42069); try { $page = $badPage->add($ct, array('uID' => 1, 'cName' => $pageName, 'cHandle' => $pageHandle)); } catch (Exception $e) { $caught = true; } if (!$caught) { $this->fail('Added a page to a non-page'); } $page = self::createPage($pageName, $pageHandle); $parentID = $page->getCollectionParentID(); $this->assertInstanceOf('Page', $page); $this->assertEquals($parentID, HOME_CID); $this->assertSame($pageName, $page->getCollectionName()); $this->assertSame($pageHandle, $page->getCollectionHandle()); $this->assertSame('/' . $pageHandle, $page->getCollectionPath()); //now we know adding pages works. $destination = self::createPage("Destination"); $parentCID = $destination->getCollectionID(); $page->move($destination); $parentPath = $destination->getCollectionPath(); $handle = $page->getCollectionHandle(); $path = $page->getCollectionPath(); $this->assertSame($parentPath . '/' . $handle, $path); $this->assertSame($parentCID, $page->getCollectionParentID()); //now we know that moving pages works $page->moveToTrash(); $this->assertTrue($page->isInTrash()); //stuff is going to the trash $cID = $page->getCollectionID(); $page->delete(); $noPage = Page::getByID($cID); $this->assertEquals(COLLECTION_NOT_FOUND, $noPage->error); //maybe there is a more certain way to determine this. //now we know deleting pages works $destination->delete(); //clean up the destination page }
public function run() { BlockType::installBlockType('tags'); BlockType::installBlockType('next_previous'); BlockType::installBlockType('date_nav'); Loader::model('collection_types'); $blogEntry = CollectionType::getByHandle('blog_entry'); if (!$blogEntry || !intval($blogEntry->getCollectionTypeID())) { $data['ctHandle'] = 'blog_entry'; $data['ctName'] = t('Blog Entry'); $blogEntry = CollectionType::add($data); } }
public function install() { Loader::model('collection_types'); $pkg = parent::install(); PageTheme::add('casual', $pkg); $pagetypearray = array(array("left_sidebar", "Left Sidebar"), array("right_sidebar", "Right Sidebar"), array("full", "One Column"), array("three_column", "Three Column Layout")); foreach ($pagetypearray as $value) { $pageType = CollectionType::getByHandle($value[0]); if (!$pageType) { $pkg = Package::getByHandle('casual'); $newPageType = CollectionType::add(array('ctHandle' => $value[0], 'ctName' => t($value[1])), $pkg); } else { $newPageType = $pageType; } } }
/** * Find the latest unstarted walk, so you don't need to make a new one. * @param $u The user for whom you're finding their walk * @return Collection */ protected function getUnstartedWalk(User $u, Page $city) { // Find all walks for this user, in this city, with no name $pl = new PageList(); $pl->filterByCollectionTypeHandle('walk'); $pl->filterByUserID($u->getUserID()); $pl->filterByParentID($city->getCollectionID()); $pl->displayUnapprovedPages(); $pl->filterByName('', true); $pl->filterByAttribute('exclude_page_list', true); // Arbitrarily use the first; it's blank anyway. $walk = $pl->get(1)[0]; // If you couldn't find a walk, make a new one in the city if (!$walk) { $walk = $city->add(CollectionType::getByHandle('walk'), []); $walk->setAttribute('exclude_page_list', true); } return $walk; }
public function do_add() { $ctName = $_POST['ctName']; $ctHandle = $_POST['ctHandle']; $vs = Loader::helper('validation/strings'); $error = array(); if (!$ctHandle) { $this->error->add(t("Handle required.")); } else { if (!$vs->handle($ctHandle)) { $this->error->add(t('Handles must contain only letters, numbers or the underscore symbol.')); } } if (CollectionType::getByHandle($ctHandle)) { $this->error->add(t('Handle already exists.')); } if (!$ctName) { $this->error->add(t("Name required.")); } else { if (preg_match('/[<>{};?"`]/i', $ctName)) { $this->error->add(t('Invalid characters in page type name.')); } } $valt = Loader::helper('validation/token'); if (!$valt->validate('add_page_type')) { $this->error->add($valt->getErrorMessage()); } $akIDArray = $_POST['akID']; if (!is_array($akIDArray)) { $akIDArray = array(); } if (!$this->error->has()) { try { if ($_POST['task'] == 'add') { $nCT = CollectionType::add($_POST); $this->redirect('/dashboard/pages/types', 'page_type_added'); } exit; } catch (Exception $e1) { $this->error->add($e1->getMessage()); } } }
private function add_personal_homepage($user_name, $nick_name, $doc_lang) { $page = Page::getByPath("/{$doc_lang}/engineer/{$user_name}"); if ($page->getCollectionID() > 0) { $this->set('error', t('Existed username: %s!', $user_name)); return false; } $page_type = CollectionType::getByHandle('personal_homepage'); $parent_page = Page::getByPath("/{$doc_lang}/engineer"); $page = $parent_page->add($page_type, array('cName' => $nick_name, 'cHandle' => $user_name)); if ($page instanceof Page) { $block_type = BlockType::getByHandle("fse_public_profile"); $area = new Area('Side Bar'); $page->addBlock($block_type, $area, array("fseUsername" => $user_name)); } else { $this->set('error', t('Failed to create personal homepage!')); return false; } return true; }
private function installPages($pkg) { // this could be any handle $boilerplate = CollectionType::getByHandle("boilerplate"); // we want the user ID of the person installing. Really, you could use // any user here if you want. $u = new User(); $uID = $u->getUserID(); // doesn't need to be home, you could install these anywhere $home = Page::getByID(HOME_CID); $data = array('cHandle' => "boilerplate-sample", 'cName' => "Boilerplate Sample", 'pkgID' => $pkg->getPackageID(), 'uID' => $uID); $boilerplateSample = $home->add($boilerplate, $data); /* * After you have added the page, you can add blocks with the same * syntax as was used in the installPageTypes function above * * $boilerplateSample->addBlock($bt, 'Area Name', $data); */ /* * It's also useful to assign attributes here, so that you don't have * to do them from the front end later. There are a lot of different * things that you can do here, these two are just to show how and where * to do it. */ $boilerplateSample->setAttribute('exclude_page_list', 1); $boilerplateSample->setAttribute('meta_description', t("A sample page created by the C5 Boilerplate package.")); }
protected function add_project_pages($project_id, $name, $short_desc) { $homepage = Page::getByPath(ProjectInfo::assemblePath($project_id, 'home')); if ($homepage->getCollectionID() > 0) { $this->set('error', t('Existed project: %s!', $project_id)); return false; } $doc_lang = substr($project_id, -2); $page_type = CollectionType::getByHandle('project_homepage'); $parent_page = Page::getByPath("/{$doc_lang}/project"); if ($parent_page->getCollectionID() == false) { $this->set('error', t('System error (no parent to create project pages)!')); return false; } $homepage = $parent_page->add($page_type, array("cName" => $name, "cHandle" => $project_id, "cDescription" => $short_desc)); if ($homepage instanceof Page) { $block_type = BlockType::getByHandle("project_banner"); $area = new Area('Banner'); $homepage->addBlock($block_type, $area, array("projectID" => $project_id)); } else { $this->set('error', t('Failed to create project homepage for %s!', $project_id)); return false; } return $this->add_requried_doc_part_pages($project_id, $homepage); }
* http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ defined('C5_EXECUTE') or die('Access Denied.'); exit(0); require_once 'helpers/fsen/ProjectInfo.php'; $short_cache_pths = array('localized_home', 'personal_homepage'); echo 'Set default cache settings for some page types... <br/>'; foreach ($short_cache_pths as $pth) { echo "=> Setting: {$pth}..."; $page_type = CollectionType::getByHandle($pth); if (!$page_type instanceof CollectionType) { echo "No such page type: {$pth}. <br/>"; continue; } $masterCID = $page_type->getMasterCollectionID(); $masterCollection = Page::getByID($masterCID); $masterCollection->update(array('cCacheFullPageContent' => 1, 'cCacheFullPageContentOverrideLifetime' => 'custom', 'cCacheFullPageContentLifetimeCustom' => 10)); echo "Done. <br/>"; flush(); ob_flush(); } echo 'Creating blog home pages for FSEs and reset the cache settings for personal homepages... <br/>'; $en_blogs_page = Page::getByPath('/en/blog'); $zh_blogs_page = Page::getByPath('/zh/blog'); $db = Loader::db();
private static function getChapterPageType($project_id, $domain_handle, $volume_handle) { if (preg_match("/^sys-[a-z]{2}\$/", $project_id)) { $page_type_handle = self::$mDomain2ChapterPageTypeMap["sys/{$domain_handle}/{$volume_handle}"]; if (!isset($page_type_handle)) { $page_type_handle = self::$mDomain2ChapterPageTypeMap["sys/{$domain_handle}"]; } } if (!isset($page_type_handle)) { $page_type_handle = self::$mDomain2ChapterPageTypeMap["{$domain_handle}/{$volume_handle}"]; if (!isset($page_type_handle)) { $page_type_handle = self::$mDomain2ChapterPageTypeMap[$domain_handle]; } } return CollectionType::getByHandle($page_type_handle); }
/** * Gets the path to a particular page type controller */ public function pageTypeControllerPath($ctHandle) { Loader::model('collection_types'); $ct = CollectionType::getByHandle($ctHandle); if (!is_object($ct)) { return false; } $pkgHandle = $ct->getPackageHandle(); if ($pkgHandle != '') { $packageDir = is_dir(DIR_PACKAGES . '/' . $pkgHandle) ? DIR_PACKAGES : DIR_PACKAGES_CORE; } if (file_exists(DIR_FILES_CONTROLLERS . "/" . DIRNAME_PAGE_TYPES . "/{$ctHandle}.php")) { $path = DIR_FILES_CONTROLLERS . "/" . DIRNAME_PAGE_TYPES . "/{$ctHandle}.php"; } else { if (isset($packageDir) && file_exists($packageDir . '/' . $pkgHandle . '/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php')) { $path = $packageDir . '/' . $pkgHandle . '/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php'; } else { if (file_exists(DIR_FILES_CONTROLLERS_REQUIRED . "/" . DIRNAME_PAGE_TYPES . "/{$ctHandle}.php")) { $path = DIR_FILES_CONTROLLERS_REQUIRED . "/" . DIRNAME_PAGE_TYPES . "/{$ctHandle}.php"; } } } return $path; }
<?php $importArray = json_decode(file_get_contents(__DIR__ . '/walkexport.json'), true); foreach ($importArray as $walk) { $pl = new PageList(); $pl->filterByCollectionTypeHandle('country'); $pl->filterByName($walk['country']); $country = $pl->get(1)[0]; if (!$country) { $country = Page::getByID(1)->add(CollectionType::getByHandle('country'), ['cName' => $walk['country']]); } $pl = new PageList(); $pl->filterByCollectionTypeHandle('city'); $pl->filterByName($walk['city']); $city = $pl->get(1)[0]; if (!$city) { $city = $country->add(CollectionType::getByHandle('city'), ['cName' => $walk['city']]); } $ui = UserInfo::getByEmail($walk['owner']); if (!$ui) { $ui = UserInfo::add(['uName' => $walk['owner'], 'uEmail' => $walk['owner']]); } $walkPage = $city->add(CollectionType::getByHandle('walk'), ['cName' => $walk['title'], 'uID' => $ui->getUserID()]); $walkController = Loader::controller($walkPage); $walkController->setJson(json_encode($walk), true); }
public static function getValue($value) { if (preg_match('/\{ccm:export:page:(.*)\}|\{ccm:export:file:(.*)\}|\{ccm:export:image:(.*)\}|\{ccm:export:pagetype:(.*)\}/i', $value, $matches)) { if ($matches[1]) { $c = Page::getByPath($matches[1]); return $c->getCollectionID(); } if ($matches[2]) { $db = Loader::db(); $fID = $db->GetOne('select fID from FileVersions where fvFilename = ?', array($matches[2])); return $fID; } if ($matches[3]) { $db = Loader::db(); $fID = $db->GetOne('select fID from FileVersions where fvFilename = ?', array($matches[3])); return $fID; } if ($matches[4]) { $ct = CollectionType::getByHandle($matches[4]); return $ct->getCollectionTypeID(); } } else { return $value; } }
} else { echo "creating: {$country->getAttribute('name')}<br/>"; $countryPage = Page::getByID(1)->add(CollectionType::getByHandle('country'), ['cName' => $country->getAttribute('name')]); } foreach ($country->getElementsByTagName('city') as $city) { $cities = new PageList(); $cities->filterByCollectionTypeHandle('city'); $cities->filterByName($city->getAttribute('name')); $cityPage = $cities->get(1)[0]; if ($cityPage) { $ui = UserInfo::getByEmail($city->getAttribute('owner_email')); echo "exists: {$cityPage->getCollectionName()} new owner: " . ($ui ? $ui->getUserID() : "") . "<br/>"; } else { echo "creating: {$city->getAttribute('name')}<br/>"; $ui = UserInfo::getByEmail($city->getAttribute('owner_email')); $cityPage = $countryPage->add(CollectionType::getByHandle('city'), ['cName' => $city->getAttribute('name'), 'uID' => $ui ? $ui->getUserID() : 1]); } $ui && $cityPage->update(['uID' => $ui->getUserID()]); } } /* foreach($user->childNodes as $attr) { if($attr->nodeName == 'social_login') { foreach($attr->childNodes as $social) { $newUser['oauth_auths'][$social->nodeName] = $social->nodeValue; } } else { $newUser[$attr->nodeName] = $attr->nodeValue; } } if(UserInfo::getByEmail($newUser['email'])) {
/** * Template Components */ // Edit if ($canEdit) { $Edit = <<<EOT <a href="{$this->url('/dashboard/composer/write/-/edit/' . $c->getCollectionID())}"><i class='fa fa-pencil-square'></i></a> EOT; } if ($c->isEditMode() || $blog) { if ($blog) { $BlogLink = $nh->getCollectionURL($blog); } if ($blog && (new Permissions($blog))->canAddSubpage()) { $BlogPostButton = <<<EOT <a class="add" href="{$this->url('/dashboard/composer/write/', CollectionType::getByHandle('city_blog_entry')->getCollectionTypeID(), $blog->getCollectionID())}"> <i class="fa fa-angle-double-right"></i> {$t('post new article')} </a> EOT; } $Blog = <<<EOT <section id="blog"> <h2 class="title"><a href="{$BlogLink}">{$t('City Blog')}</a> {$BlogPostButton} </h2> {$area('City Blog')} </section> EOT; } // Background Photo if ($bgPhotoCreditName && $bgPhotoCreditName) {
/** * Gets the path to a particular page type controller */ public function pageTypeControllerPath($ctHandle) { self::model('collection_types'); $ct = CollectionType::getByHandle($ctHandle); if (!is_object($ct)) { return false; } $pkgHandle = $ct->getPackageHandle(); $env = Environment::get(); $path = $env->getPath(DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php', $pkgHandle); if (file_exists($path)) { return $path; } }
$localized_projects_page = Page::getByPath('/' . $lang['home_handle'] . '/project'); if ($localized_projects_page->getCollectionID() == false) { $localized_projects_page = $localized_home_page->add($page_type, array("cHandle" => $lang['projects_handle'], "cName" => $lang['projects_name'], "cDescription" => $lang['projects_desc'])); if ($localized_projects_page->getCollectionID() == false) { echo 'Error: failed to crate localized projects page. <br/>'; exit(0); } } echo 'Done <br/>'; flush(); ob_flush(); echo '<br/>'; echo 'Creating localized engineers page for '; echo $lang['home_handle']; echo '... '; $page_type = CollectionType::getByHandle('localized_engineers'); if (!$page_type instanceof CollectionType) { echo 'Error: failed to get page type for localized engineers page.'; exit(0); } $localized_engineers_page = Page::getByPath('/' . $lang['home_handle'] . '/engineer'); if ($localized_engineers_page->getCollectionID() == false) { $localized_engineers_page = $localized_home_page->add($page_type, array("cHandle" => $lang['engineers_handle'], "cName" => $lang['engineers_name'], "cDescription" => $lang['engineers_desc'])); if ($localized_engineers_page->getCollectionID() == false) { echo 'Error: failed to create localized engineers page. <br/>'; exit(0); } } echo 'Done <br/>'; flush(); ob_flush();