/** * Creates a new weblogs.com pinger * * @param SiteApplication $app * @param BlorgPost $post * @param string $base_href optional. If not specified, the base href is * build from the application. */ public function __construct(SiteApplication $app, BlorgPost $post, $base_href = null) { $this->app = $app; $this->post = $post; if ($base_href === null) { $this->base_href = $app->getBaseHref() . $app->config->blorg->path; } else { $this->base_href = strval($base_href); } $this->client = XML_RPC2_Client::create(self::WEBLOGS_DOT_COM_SERVER, array('prefix' => 'weblogUpdates.', 'encoding' => 'utf-8')); }
public static function getDefaultList(SiteApplication $app, SiteInstance $instance = null) { $default_list = $app->config->mail_chimp->default_list; if ($app->hasModule('SiteMultipleInstanceModule') && $app->getInstance() === null) { if ($instance === null) { throw new DeliveranceException('Instance must be set.'); } $sql = 'select value from InstanceConfigSetting where name = %s and instance = %s'; $sql = sprintf($sql, $app->db->quote('mail_chimp.default_list', 'text'), $app->db->quote($instance->id, 'integer')); $default_list = SwatDB::queryOne($app->db, $sql); } return $default_list; }
protected function initInternal() { parent::initInternal(); $this->parent = SiteApplication::initVar('parent'); $form = $this->ui->getWidget('order_form'); $form->addHiddenField('parent', $this->parent); }
function printContent() { echo "Application [" . $this->asked_app . "] Access denied<br/>----<br/>"; echo "Please <a href=\"" . $this->site->applicationUrl("sign") . "?op=login\">login</a><br/>"; echo "Back to [<a href=\"" . $this->site->applicationUrl($this->asked_app) . "\">Back</a>] <br/>"; parent::printContent(); }
protected function initReport() { $quarter = SiteApplication::initVar('quarter', null, SiteApplication::VAR_GET); if ($quarter === null || preg_match('/^2[0-9]{3}-0[1-4]$/', $quarter) === 0) { throw new AdminNotFoundException('Invalid quarter.'); } list($year, $quarter) = explode('-', $quarter, 2); $start_month = (intval($quarter) - 1) * 3 + 1; $quarter = new SwatDate(); $quarter->setTime(0, 0, 0); $quarter->setDate($year, $start_month, 1); $quarter->setTZ($this->app->default_time_zone); $quarter->toUTC(); $type = SiteApplication::initVar('type', null, SiteApplication::VAR_GET); $provider = new CMEProvider(); $provider->setDatabase($this->app->db); if (!$provider->loadByShortname($type)) { throw new AdminNotFoundException('Invalid CME provider.'); } $sql = sprintf('select * from QuizReport where quarter = %s and provider = %s', $this->app->db->quote($quarter->getDate(), 'date'), $this->app->db->quote($provider->id, 'integer')); $this->report = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMEQuizReportWrapper'))->getFirst(); if (!$this->report instanceof CMEQuizReport) { throw new AdminNotFoundException(sprintf('Report not found for quarter %s.', $quarter->getDate())); } $this->report->setFileBase('../../system/quiz-report-updater'); if (!file_exists($this->report->getFilePath())) { throw new AdminNotFoundException(sprintf('Report file ‘%s’ not found', $this->report->getFilePath())); } }
protected function initInternal() { parent::initInternal(); $this->ui->loadFromXML($this->ui_xml); $this->id = SiteApplication::initVar('id'); $this->initTag(); }
/** * Creates a new Atom post page * * @param SiteWebApplication $app the application. * @param SiteLayout $layout * @param string $dimension_shortname */ public function __construct(SiteWebApplication $app, SiteLayout $layout, array $arguments = array()) { $layout = new SiteLayout($app, 'Site/layouts/xhtml/atom.php'); parent::__construct($app, $layout, $arguments); $tags = SiteApplication::initVar('tags'); $this->createTagList($tags); $this->dimension = $this->initDimension($this->getArgument('dimension_shortname')); }
protected function initInternal() { parent::initInternal(); $this->id = SiteApplication::initVar('id'); $this->ui->loadFromXML($this->getUiXml()); $this->initNewsletter(); $this->updateNewsletterStats(); }
protected function initFrontMatter() { if ($this->isNew()) { $front_matter_id = SiteApplication::initVar('front-matter'); $class_name = SwatDBClassMap::get('CMEFrontMatter'); $this->credit->front_matter = new $class_name(); $this->credit->front_matter->setDatabase($this->app->db); if (!$this->credit->front_matter->load($front_matter_id)) { throw new AdminNotFoundException(sprintf('A CME front matter with the id of ‘%s’ does not ' . 'exist.', $front_matter_id)); } } }
function printContent() { echo "<h1>Index page</h1>"; echo $this->site; $user = $this->site->username(); if (isset($user)) { echo " <a href='index.php?" . FMWK_PARAM_APP . "=sign&" . FMWK_PARAM_OP . "=logout&asked_app=" . $this->name . "'>sign out</a>"; } else { echo " <a href='index.php?" . FMWK_PARAM_APP . "=sign&" . FMWK_PARAM_OP . "=login&asked_app=" . $this->name . "'>sign in</a>"; } echo "<br/>"; parent::printContent(); }
protected function loadPost() { $id = SiteApplication::initVar('id'); $post_class = SwatDBClassMap::get('BlorgPost'); $this->post = new $post_class(); $this->post->setDatabase($this->app->db); if (!$this->post->load($id)) { throw new AdminNotFoundException(sprintf(Blorg::_('A post with an id of ‘%d’ does not exist.'), $id)); } $instance_id = $this->post->getInternalValue('instance'); if ($instance_id !== $this->app->getInstanceId()) { throw new AdminNotFoundException(sprintf(Blorg::_('A post with an id of ‘%d’ does not exist.'), $id)); } }
protected function initInternal() { parent::initInternal(); $this->id = SiteApplication::initVar('id'); $this->initTag(); $this->ui->loadFromXML($this->ui_xml); $instance_id = $this->app->getInstanceId(); $this->ui->getWidget('passphrase_field')->visible = $this->app->config->pinhole->passphrase === null; // setup tag entry control $this->ui->getWidget('tags')->setApplication($this->app); $this->ui->getWidget('tags')->setAllTags(); // setup status list $status_flydown = $this->ui->getWidget('status_flydown'); $status_flydown->addOptionsByArray(PinholePhoto::getStatuses()); }
protected function getJSONResponse() { // remember per-question timestamps to handle race conditions if (!isset($this->app->session->quiz_question_timestamp)) { $this->app->session->quiz_question_timestamp = new ArrayObject(); } $quiz_question_timestamp = $this->app->session->quiz_question_timestamp; $transaction = new SwatDBTransaction($this->app->db); try { if (!$this->app->session->isLoggedIn()) { return $this->getErrorResponse('Not logged in.'); } $account = $this->app->session->account; $quiz = $this->getQuiz($this->getProgress($this->getCredits())); if (!$quiz instanceof CMEQuiz) { return $this->getErrorResponse('Quiz not found.'); } $binding_id = SiteApplication::initVar('binding_id', null, SiteApplication::VAR_POST); if ($binding_id === null) { return $this->getErrorResponse('Question binding not specified.'); } $binding = $this->getQuestionBinding($quiz, $binding_id); $timestamp = SiteApplication::initVar('timestamp', null, SiteApplication::VAR_POST); if ($timestamp === null) { return $this->getErrorResponse('Timestamp not specified.'); } if (isset($quiz_question_timestamp[$binding_id]) && $timestamp < $quiz_question_timestamp[$binding_id]) { return $this->getErrorResponse('Request is out of sequence.'); } $quiz_question_timestamp[$binding_id] = $timestamp; $option_id = SiteApplication::initVar('option_id', null, SiteApplication::VAR_POST); if ($option_id === null) { return $this->getErrorResponse('Response option id not specified.'); } $response = $this->getResponse($quiz); $response_value = $this->getResponseValue($quiz, $response, $binding, $option_id); if ($response_value === null) { return $this->getErrorResponse('Response option id not valid for the specified question.'); } $this->saveResponseValue($response, $response_value); $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); throw $e; } return array('status' => array('code' => 'ok', 'message' => ''), 'timestamp' => time()); }
protected function initPhoto() { $id = SiteApplication::initVar('id'); $class_name = SwatDBClassMap::get('PinholePhoto'); $this->photo = new $class_name(); $this->photo->setDatabase($this->app->db); if ($id === null) { throw new AdminNoAccessException(Pinhole::_('A Photo id is required.')); } else { $instance_id = $this->app->getInstanceId(); if (!$this->photo->load($id)) { throw new AdminNotFoundException(sprintf(Pinhole::_('Photo with id “%s” not found.'), $id)); } elseif ($this->photo->image_set->instance !== null && $this->photo->image_set->instance->id != $instance_id) { throw new AdminNotFoundException(sprintf(Pinhole::_('Photo with id “%s” loaded ' . 'in the wrong instance.'), $id)); } } }
protected function initInternal() { $this->ui_xml = dirname(__FILE__) . '/merge.xml'; parent::initInternal(); $id = SiteApplication::initVar('id', null, SiteApplication::VAR_GET); if ($id !== null) { $this->setItems(array($id)); } if (count($this->items) != 1) { throw new SiteNotFoundException('Only 1 id at a time!'); } foreach ($this->items as $item) { $id = $item; } $this->source_tag = $this->getTag($id); $this->ui->getWidget('dst_tag')->setApplication($this->app); $this->ui->getWidget('dst_tag')->setAllTags(); }
protected function initInternal() { AdminIndex::initInternal(); $this->id = SiteApplication::initVar('id'); if (is_numeric($this->id)) { $this->id = intval($this->id); } $this->initCredit(); $this->initInquisition(); $this->ui->loadFromXML($this->getUiXml()); $local_ui = new SwatUI(); $local_ui->loadFromXML($this->getCreditDetailsViewXml()); $provider_titles = array(); foreach ($this->credit->front_matter->providers as $provider) { $provider_titles[] = $provider->credit_title_plural; } $local_ui->getWidget('details_view')->getField('hour')->title = SwatString::toList($provider_titles); $view = $this->ui->getWidget('details_view'); foreach ($local_ui->getWidget('details_view')->getFields() as $field) { $view->appendField($field); } }
protected function getXML($force_cache_update) { $cache_key = $this->getCacheKey(); $expiry_key = $this->getCacheExpiryKey(); $expired = $force_cache_update || $this->app->getCacheValue($expiry_key); if ($expired === false) { // expiry key expired, check for updated content on Tumblr $xml = $this->getTumblrXML(); if ($xml === false) { // Tumblr API is down, try long cached value $xml = $this->app->getCacheValue($cache_key); if ($xml === false) { // Tumblr API is down, but we have no cached value $xml = ''; } } else { // update long cache with new Tumblr content $this->app->addCacheValue($xml, $cache_key, null, 7200); } // update expiry cache value $this->app->addCacheValue('1', $expiry_key, null, 300); } else { // expiry key not expired, check for long cached value $xml = $this->app->getCacheValue($cache_key); if ($xml === false) { // long cached version expired or does not exist, check // for content on Tumblr $xml = $this->getTumblrXML(); if ($xml === false) { // Tumblr API is down, but we have no cached value $xml = ''; $this->app->deleteCacheValue($expiry_key); } else { // update long cache with new Tumblr content $this->app->addCacheValue($xml, $cache_key, null, 7200); } } } return $xml; }
function printOutput() { if (empty($this->output)) { if ($this->use_tpl_engine) { $this->prepareTplEngine(); $this->tpl_engine->pparse("Output", "CommonTemplate"); } else { parent::printOutput(); } } }
/** * Display an ad * * If $config->blorg->ad_referers_only is true, the referer's domain is * checked against the site's domain to ensure the page has been arrived at * via another site. * * @param SiteApplication $app The current application * @param string $ad_type The type of ad to display */ public static function displayAd(SiteApplication $app, $type) { $type_name = 'ad_' . $type; if ($app->config->blorg->{$type_name} != '') { $base_href = $app->getBaseHref(); $referer = SiteApplication::initVar('HTTP_REFERER', null, SiteApplication::VAR_SERVER); // Display ad if referers only is off OR if there is a referer and // it does not start with the app base href. if (!$app->config->blorg->ad_referers_only || $referer !== null && strncmp($referer, $base_href, strlen($base_href)) != 0) { echo '<div class="ad">'; echo $app->config->blorg->{$type_name}; echo '</div>'; } } }
function printContent() { parent::printContent(); echo "Administration panel<br/>"; }
protected function getCacheKey($method_name, array $args = array()) { /* both (string)$this and the tag get var are needed to make the cache key unique. We need the get var for page tags that are removed, and $this->tags for when the tag list is duplicated and manipulated. */ $tags = SiteApplication::initVar('tags'); return sprintf('PinholeTagList.%s.%s.%s.%s.%s', (string) $this, (string) $tags, $method_name, md5(serialize($args)), $this->show_private_photos ? 'private' : 'public'); }
protected function buildForm(SwatForm $form) { parent::buildForm($form); $email = SiteApplication::initVar('email'); if (strlen($email) > 0) { $this->ui->getWidget('email')->value = $email; } elseif (!$form->isProcessed() && $this->app->session->isLoggedIn()) { $this->ui->getWidget('email')->value = $this->app->session->account->email; } }
function printContent() { echo "Back to [<a href=\"" . $this->site->applicationUrl($this->asked_app) . "\">Back</a>] <br/>"; $op = $this->wop; switch ($op) { case 'logout': echo "You are not logged out<br/>"; break; case 'login': echo "You are now logged in as [" . $this->wusername . "]<br/>"; break; case 'info': if ($this->user_signed) { ?> <form action="<?php echo $this->site->applicationUrl("sign"); ?> " method="post"> <div style="border: solid 1px #ccc; padding: 5px; margin: 5px; background-color: #ffeecc;"> <?php if (!empty($this->message)) { echo $this->message; } ?> <p>Username : <input type="text" name="username" value="<?php echo $this->wusername; ?> " /></p> <input type="submit" name="<?php echo FMWK_PARAM_OP; ?> " value="logout" /> </form> <?php break; } case 'sign': default: ?> <form action="<?php echo $this->site->applicationUrl("sign"); ?> " method="post"> <input type="hidden" name="asked_app" value="<?php echo $this->asked_app; ?> " /> <div style="border: solid 1px #ccc; padding: 5px; margin: 5px; background-color: #ffeecc;"> <?php if (!empty($this->message)) { echo $this->message; } ?> <p>Username : <input type="text" name="username" value="<?php echo $this->wusername; ?> " /></p> <p>Password : <input type="password" name="password" value="" /></p> <input type="submit" name="<?php echo FMWK_PARAM_OP; ?> " value="login" /> </div> </form> <?php break; } parent::printContent(); }
function __construct() { parent::__construct(new ApplicationRouter()); }
function printContent() { echo "Application [" . $this->asked_app . "] Not Found<br/>----<br/>"; parent::printContent(); }
protected function initInternal() { parent::initInternal(); $this->post_id = SiteApplication::initVar('post_id', null, SiteApplication::VAR_GET); $this->form_unique_id = SiteApplication::initVar('form_unique_id', null, SiteApplication::VAR_GET); }
public static function isShortnameValid(SiteApplication $app, BlorgPost $post) { // get publish date in local time if ($post->publish_date === null) { $publish_date = new SwatDate(); $publish_date->convertTZ($app->default_time_zone); } else { $publish_date = clone $post->publish_date; $publish_date->setTZ($app->default_time_zone); } $instance_id = $app->getInstanceId(); $sql = 'select shortname from BlorgPost where shortname = %s and instance %s %s and id %s %s and date_trunc(\'month\', convertTZ(publish_date, %s)) = date_trunc(\'month\', timestamp %s)'; $sql = sprintf($sql, $app->db->quote($post->shortname, 'text'), SwatDB::equalityOperator($instance_id), $app->db->quote($instance_id, 'integer'), SwatDB::equalityOperator($post->id, true), $app->db->quote($post->id, 'integer'), $app->db->quote($publish_date->getTimezone()->getName(), 'text'), $app->db->quote($publish_date->getDate(), 'date')); $query = SwatDB::query($app->db, $sql); return count($query) == 0; }
function __construct() { parent::__construct(new PhoebiusRouter()); }
function printContent() { echo "Page de test<br/>"; parent::printContent(); }
protected function addToSearchQueue(SiteApplication $app) { $app->addToSearchQueue('post', $this->post->id); $app->addToSearchQueue('comment', $this->id); }