本文整理汇总了PHP中Indexer::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Indexer::instance方法的具体用法?PHP Indexer::instance怎么用?PHP Indexer::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Indexer
的用法示例。
在下文中一共展示了Indexer::instance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: instance
public static function instance()
{
if (self::$instance == null) {
self::$instance = new Indexer();
}
return self::$instance;
}
示例2: createSiteEvent
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
//.........这里部分代码省略.........
示例3: cloneSite
public function cloneSite($site, $siteProperties, $attrs = array())
{
$db = Database::connection();
$db->begin();
/*
* Hopefully attrs contains a set of parameters that determine
* the behoviour of the duplicatior.
*/
$nsite = clone $site;
$nsite->setNew(true);
$nsite->setSiteId(null);
$nsite->setUnixName($siteProperties['unixname']);
if (isset($siteProperties['name'])) {
$nsite->setName($siteProperties['name']);
}
if (isset($siteProperties['subtitle'])) {
$nsite->setSubtitle($siteProperties['subtitle']);
}
if (isset($siteProperties['description'])) {
$nsite->setDescription($siteProperties['description']);
}
if (array_key_exists('private', $siteProperties)) {
if ($siteProperties['private']) {
$nsite->setPrivate(true);
} else {
$nsite->setPrivate(false);
}
}
$nsite->setCustomDomain(null);
$nsite->save();
/* Super settings. */
// site_super_settings
$superSettings = $site->getSuperSettings();
$superSettings->setNew(true);
$superSettings->setSiteId($nsite->getSiteId());
$superSettings->save();
/* Site settings. */
$settings = $site->getSettings();
$settings->setNew(true);
$settings->setSiteId($nsite->getSiteId());
$settings->save();
/* Now handle site owner. */
$c = new Criteria();
$c->add('site_id', $site->getSiteId());
$c->add('founder', true);
$owner = DB_AdminPeer::instance()->selectOne($c);
$this->owner = $owner;
$admin = new DB_Admin();
$admin->setSiteId($nsite->getSiteId());
$admin->setUserId($owner->getUserId());
$admin->setFounder(true);
// will be nonremovable ;-)
$admin->save();
$member = new DB_Member();
$member->setSiteId($nsite->getSiteId());
$member->setUserId($owner->getUserId());
$member->setDateJoined(new ODate());
$member->save();
/* Theme(s). */
$c = new Criteria();
$c->add('site_id', $site->getSiteId());
$themes = DB_ThemePeer::instance()->select($c);
$themeMap = array();
$nthemes = array();
foreach ($themes as $theme) {
$ntheme = clone $theme;
$ntheme->setNew(true);
$ntheme->setSiteId($nsite->getSiteId());
$ntheme->setThemeId(null);
$ntheme->save();
$themeMap[$theme->getThemeId()] = $ntheme->getThemeId();
$nthemes[] = $ntheme;
}
foreach ($nthemes as $ntheme) {
if ($ntheme->getExtendsThemeId() && isset($themeMap[$ntheme->getExtendsThemeId()])) {
$ntheme->setExtendsThemeId($themeMap[$ntheme->getExtendsThemeId()]);
$ntheme->save();
}
}
// get all categories from the site
$c = new Criteria();
$c->add("site_id", $site->getSiteId());
$categories = DB_CategoryPeer::instance()->select($c);
foreach ($categories as $cat) {
if (!in_array($cat->getName(), $this->excludedCategories)) {
$ncategory = $this->duplicateCategory($cat, $nsite);
/* Check if is using a custom theme. */
if ($ncategory->getThemeId() && isset($themeMap[$ncategory->getThemeId()])) {
$ncategory->setThemeId($themeMap[$ncategory->getThemeId()]);
$ncategory->save();
}
if ($ncategory->getTemplateId()) {
$ncategory->setTemplateId($this->pageMap[$ncategory->getTemplateId()]);
$ncategory->save();
}
}
}
/* Recompile WHOLE site. */
$od = new Outdater();
$od->recompileWholeSite($nsite);
//.........这里部分代码省略.........
示例4: deletePostEvent
public function deletePostEvent($runData)
{
$pl = $runData->getParameterList();
$site = $runData->getTemp("site");
$postId = $pl->getParameterValue("postId");
if ($postId == null || !is_numeric($postId)) {
throw new ProcessException(_("No such post."), "no_post");
}
$db = Database::connection();
$db->begin();
$post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId);
if ($post == null || $post->getSiteId() != $site->getSiteId()) {
throw new ProcessException(_("No such post."), "no_post");
}
$thread = $post->getForumThread();
$category = $thread->getForumCategory();
try {
WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category);
} catch (Exception $e) {
throw new WDPermissionException(_("Sorry, you are not allowed to delete posts. Only site administrators and moderators are the ones who can."));
}
$c = new Criteria();
$c->add("parent_id", $postId);
$toDelete = array();
$chposts = DB_ForumPostPeer::instance()->select($c);
while ($chposts && count($chposts) > 0) {
$toDelete = array_merge($toDelete, $chposts);
$c = new Criteria();
foreach ($chposts as $f) {
$c->addOr("parent_id", $f->getPostId());
}
$chposts = DB_ForumPostPeer::instance()->select($c);
}
DB_ForumPostPeer::instance()->deleteByPrimaryKey($post->getPostId());
foreach ($toDelete as $f) {
DB_ForumPostPeer::instance()->deleteByPrimaryKey($f->getPostId());
}
// now recalculate a few things...
$thread->calculateNumberPosts();
$thread->findLastPost();
$thread->save();
$category->calculateNumberPosts();
$category->findLastPost();
$category->save();
// outdate
$o = new Outdater();
$o->forumEvent("thread_save", $thread);
// index thread
Indexer::instance()->indexThread($thread);
EventLogger::instance()->logPostDelete($thread, $post->getTitle());
$db->commit();
if (GlobalProperties::$UI_SLEEP) {
sleep(1);
}
}
示例5: indexPage
public function indexPage($page)
{
Indexer::instance()->indexPage($page);
}