/** * Build Newsletter Content * * @param object $campaign Campaign Object * @param boolean $stripHtmlAndBodyTags Strip out <html> & <body> tags? * @return string Campaign HTML */ public function buildNewsletter($campaign, $stripHtmlAndBodyTags = false) { //are we overriding content with template vs using stories? if ($campaign->template == '-1') { $campaignTemplate = $campaign->html_content; $campaignPrimaryStories = ''; $campaignSecondaryStories = ''; } else { //instantiate objects $newsletterTemplate = new Template($this->_db); $newsletterPrimaryStory = new PrimaryStory($this->_db); $newsletterSecondaryStory = new SecondaryStory($this->_db); //get the campaign template $newsletterTemplate->load($campaign->template); $campaignTemplate = $newsletterTemplate->template; //get primary & secondary colors $primaryTitleColor = $newsletterTemplate->primary_title_color ? $newsletterTemplate->primary_title_color : '#000000'; if (strlen($primaryTitleColor) <= 7 && !strstr($primaryTitleColor, ';')) { $primaryTitleColor = 'font-size:20px;font-weight:bold;color:' . $primaryTitleColor . ';font-family:arial;line-height:100%;margin-bottom:10px;'; } $primaryTextColor = $newsletterTemplate->primary_text_color ? $newsletterTemplate->primary_text_color : '#444444'; if (strlen($primaryTextColor) <= 7 && !strstr($primaryTextColor, ';')) { $primaryTextColor = 'font-size:14px;font-weight:normal;color:' . $primaryTextColor . ';font-family:arial;margin-bottom:50px;'; } $secondaryTitleColor = $newsletterTemplate->secondary_title_color ? $newsletterTemplate->secondary_title_color : '#666666'; if (strlen($secondaryTitleColor) <= 7 && !strstr($secondaryTitleColor, ';')) { $secondaryTitleColor = 'font-size:15px;font-weight:bold;color:' . $secondaryTitleColor . ';font-family:arial;line-height:150%;'; } $secondaryTextColor = $newsletterTemplate->secondary_text_color ? $newsletterTemplate->secondary_text_color : '#999999'; if (strlen($secondaryTextColor) <= 7 && !strstr($secondaryTextColor, ';')) { $secondaryTextColor = 'font-size:12px;color:' . $secondaryTextColor . ';font-family:arial;'; } //get and format primary stories $campaignPrimaryStories = ''; $primaryStories = $newsletterPrimaryStory->getStories($campaign->id); foreach ($primaryStories as $pStory) { $campaignPrimaryStories .= '<span style="display:block;page-break-inside:avoid;' . $primaryTitleColor . '">'; $campaignPrimaryStories .= $pStory->title; $campaignPrimaryStories .= '</span>'; $campaignPrimaryStories .= '<span style="display:block;page-break-inside:avoid;' . $primaryTextColor . '">'; $campaignPrimaryStories .= $pStory->story; //do we have a readmore link if ($pStory->readmore_link) { $readmore_title = $pStory->readmore_title ? $pStory->readmore_title : 'Read More ›'; $campaignPrimaryStories .= "<br /><br /><a href=\"{$pStory->readmore_link}\" target=\"\">{$readmore_title}</a>"; } $campaignPrimaryStories .= '</span>'; } //get secondary stories $campaignSecondaryStories = '<br /><br />'; $secondaryStories = $newsletterSecondaryStory->getStories($campaign->id); foreach ($secondaryStories as $sStory) { $campaignSecondaryStories .= '<span style="display:block;page-break-inside:avoid;' . $secondaryTitleColor . '">'; $campaignSecondaryStories .= $sStory->title; $campaignSecondaryStories .= '</span>'; $campaignSecondaryStories .= '<span style="display:block;page-break-inside:avoid;' . $secondaryTextColor . '">'; $campaignSecondaryStories .= $sStory->story; //do we have a readmore link if ($sStory->readmore_link) { $readmore_title = $sStory->readmore_title ? $sStory->readmore_title : 'Read More ›'; $campaignSecondaryStories .= "<br /><br /><a href=\"{$sStory->readmore_link}\" target=\"\">{$readmore_title}</a>"; } $campaignSecondaryStories .= '</span>'; $campaignSecondaryStories .= '<br /><br />'; } } //get the hub $hub = $_SERVER['SERVER_NAME']; //build link to newsletters for email $link = 'https://' . $hub . '/newsletter/' . $campaign->alias; //replace placeholders in template $campaignParsed = str_replace("{{LINK}}", $link, $campaignTemplate); $campaignParsed = str_replace("{{ALIAS}}", $campaign->alias, $campaignParsed); $campaignParsed = str_replace("{{TITLE}}", $campaign->name, $campaignParsed); $campaignParsed = str_replace("{{ISSUE}}", $campaign->issue, $campaignParsed); // Handle the AUTOGEN sections if (preg_match_all("(\\{.*?\\}\\})", $campaignPrimaryStories, $matches) !== FALSE) { foreach ($matches[0] as &$match) { // A field to hold HTML content for the section $html = ''; // Hold onto the original token $originMatch = $match; // Perform some cleanup, stripping $match = ltrim($match, "{{"); $match = rtrim($match, "}}"); // Explode on the delimiter $parts = explode("_", $match); // Make sure we're doing "it" on the right token if ($parts[0] == "AUTOGEN") { // Get the content $enabledPlugins = Event::trigger('newsletter.onGetEnabledDigests'); // Ascertain the key, based on plugin ordering $key = array_keys($enabledPlugins, strtolower($parts[1]))[0]; // Get the content for the desired plugin $content = Event::trigger('newsletter.onGetLatest', array($parts[2]))[$key]; // Apply the view template $view = new \Hubzero\Component\View(array()); // Written emphatically, set the paths and whatnot $view->setName('storytemplates'); $view->setLayout(strtolower($parts[3])); $view->setBasePath(PATH_CORE . DS . 'components' . DS . 'com_newsletter' . DS . 'admin'); // Pass the object through to the view $view->object = $content; $view->addTemplatePath(PATH_CORE . DS . 'components' . DS . 'com_newsletter' . DS . 'admin' . DS . 'views' . DS . 'storytemplates' . DS . 'tmpl'); // Oh, what's this a buffer hijack? ob_start(); // Render the view within the buffer. $view->display(); // Grab the buffer's content $html = ob_get_contents(); // Clear and close the buffer ob_end_clean(); // Do some string replacement on the original token. $campaignPrimaryStories = str_replace($originMatch, $html, $campaignPrimaryStories); } } } $campaignParsed = str_replace("{{PRIMARY_STORIES}}", $campaignPrimaryStories, $campaignParsed); $campaignParsed = str_replace("{{SECONDARY_STORIES}}", $campaignSecondaryStories, $campaignParsed); $campaignParsed = str_replace("{{COPYRIGHT}}", date("Y"), $campaignParsed); $campaignParsed = str_replace('src="/site', 'src="' . substr(PATH_APP, strlen(PATH_ROOT)) . '/site', $campaignParsed); //replace .org, .com., .net, .edu 's // if ($campaign->type == 'html') // { // $campaignParsed = str_replace(".org", "​.org", $campaignParsed); // $campaignParsed = str_replace(".com", "​.com", $campaignParsed); // $campaignParsed = str_replace(".net", "​.net", $campaignParsed); // $campaignParsed = str_replace(".edu", "​.edu", $campaignParsed); // } //do we want to strip <html> & <body> tags if ($stripHtmlAndBodyTags) { $campaignParsed = preg_replace('/<html[^>]*>/', '', $campaignParsed); $campaignParsed = preg_replace('/<body[^>]*>/', '', $campaignParsed); $campaignParsed = str_replace('</body>', '', $campaignParsed); $campaignParsed = str_replace('</html>', '', $campaignParsed); } return $campaignParsed; }
*/ // No direct access defined('_HZEXEC_') or die; $states = Cart_Helper::getUsStates(); $this->css(); ?> <header id="content-header"> <h2>Checkout: shipping information</h2> </header> <?php if (!empty($this->notifications)) { $view = new \Hubzero\Component\View(array('name' => 'shared', 'layout' => 'notifications')); $view->notifications = $this->notifications; $view->display(); } ?> <section class="main section"> <div class="section-inner"> <?php $errors = $this->getError(); if (!empty($errors)) { foreach ($errors as $error) { echo '<p class="error">' . $error . '</p>'; } } ?> <div class="grid"> <div class="col span6">
/** * Fetch AutoContent (from plugin) Task * * @return void */ public function fetchAutoContentTask() { // Prevent direct access if (User::isGuest()) { return false; } // Request the source variable $source = Request::getVar('source', ''); $layout = Request::getVar('layout', ''); $itemCount = Request::getInt('itemCount', 5); // Make sure we have something to work with if ($source != '' && $layout != '') { // Get a list of enabled plugins $enabledSources = Event::trigger('newsletter.onGetEnabledDigests'); // Get the matching source's ID, based on plugin ordering $matches = array_keys($enabledSources, $source); $key = $matches[0]; // Get the latest content $obj = new stdClass(); $obj = Event::trigger('newsletter.onGetLatest', array($itemCount)); // Only get the portion we are working with $obj = $obj[$key]; // Instantiate the desired Story Layout view $view = new \Hubzero\Component\View(array('name' => 'storytemplates', 'layout' => $layout)); // Pass the data through to the view $view->object = $obj; $html = $view->display(); echo $html; exit; } else { // Output a warning echo json_encode(array('status' => 'nothing specified')); exit; } }
/** * Serve publication content * Determine how to render depending on master type, attachment type and user choice * Defaults to download * * @return void */ public function serveTask() { // Incoming $aid = Request::getInt('a', 0); // Attachment id $elementId = Request::getInt('el', 1); // Element id $render = Request::getVar('render', ''); $vid = Request::getInt('vid', ''); $file = Request::getVar('file', ''); $disp = Request::getVar('disposition'); $disp = in_array($disp, array('inline', 'attachment')) ? $disp : 'attachment'; // Get our model and load publication data $this->model = new Models\Publication($this->_identifier, $this->_version, $vid); if (!$this->model->exists() || $this->model->isDeleted()) { App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_PUBLICATIONS_RESOURCE_NOT_FOUND'), 'error'); return; } // Is the visitor authorized to view content? if (!$this->model->access('view-all')) { $this->_blockAccess(); return true; } // Set curation $this->model->setCuration(); // Bundle requested? if ($render == 'archive') { // Produce archival package if ($this->model->_curationModel->package()) { // Log access if ($this->model->isPublished()) { $this->model->logAccess('primary'); } $this->model->_curationModel->serveBundle(); return; } else { throw new Exception(Lang::txt('COM_PUBLICATIONS_ERROR_FINDING_ATTACHMENTS'), 404); return; } } // Bundle requested? if ($render == 'showcontents') { // Produce archival package if ($this->model->_curationModel->package()) { // Build the HTML of the "about" tab $view = new \Hubzero\Component\View(['name' => 'view', 'layout' => '_contents']); $view->model = $this->model; $view->option = $this->_option; $view->display(); return; } else { throw new Exception(Lang::txt('COM_PUBLICATIONS_ERROR_FINDING_ATTACHMENTS'), 404); return; } } // Serving data file (dataview) if ($file) { // Ensure the file exist if (!file_exists($this->model->path('data', true) . DS . trim($file))) { throw new Exception(Lang::txt('COM_PUBLICATIONS_ERROR_FINDING_ATTACHMENTS'), 404); return; } // Initiate a new content server and serve up the file $server = new \Hubzero\Content\Server(); $server->filename($this->model->path('data', true) . DS . trim($file)); $server->disposition($disp); $server->acceptranges(true); $server->saveas(basename($file)); if (!$server->serve()) { // Should only get here on error throw new Exception(Lang::txt('COM_PUBLICATIONS_SERVER_ERROR'), 404); } else { exit; } } $this->model->attachments(); // Individual attachment is requested? Find element ID if ($aid) { $elementId = $this->model->_curationModel->getElementIdByAttachment($aid); } // We do need attachments if (!isset($this->model->_attachments['elements'][$elementId]) || empty($this->model->_attachments['elements'][$elementId])) { throw new Exception(Lang::txt('COM_PUBLICATIONS_ERROR_FINDING_ATTACHMENTS'), 404); return; } // Get element manifest to deliver content as intended $curation = $this->model->_curationModel->getElementManifest($elementId); // We do need manifest! if (!$curation || !isset($curation->element) || !$curation->element) { return false; } // Get attachment type model $attModel = new Models\Attachments($this->database); // Log access if ($this->model->isPublished()) { $aType = $curation->element->params->role == 1 ? 'primary' : 'support'; $this->model->logAccess($aType); } // Serve content $content = $attModel->serve($curation->element->params->type, $curation->element, $elementId, $this->model, $curation->block->params, $aid); // No content served if ($content === NULL || $content == false) { throw new Exception(Lang::txt('COM_PUBLICATIONS_ERROR_FINDING_ATTACHMENTS'), 404); } // Do we need to redirect to content? if ($attModel->get('redirect')) { App::redirect($attModel->get('redirect')); return; } return $content; }
/** * Display collection * * @param $cId * @return void */ private function browseCollection($cId) { $view = new \Hubzero\Component\View(array('name' => 'browse', 'layout' => 'collection')); // Get the collection products $this->warehouse->addLookupCollection($cId); $products = $this->warehouse->getProducts(); $view->products = $products; // Breadcrumbs //$this->pathway->addItem('Browsing collection', Route::url('index.php?id=' . '5')); if (Pathway::count() <= 0) { Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option); } Pathway::append(Lang::txt('COM_STOREFRONT_BROWSING_COLLECTION')); $view->display(); }
/** * Error view * * @param string $layout * @return void */ protected function _showError($layout = 'default') { // Need to be project creator $view = new \Hubzero\Component\View(array('name' => 'error', 'layout' => $layout)); $view->error = $this->getError(); $view->title = $this->title; $view->display(); return; }
/** * Project view * * @return void */ public function viewTask() { // Incoming $preview = Request::getInt('preview', 0); $this->active = Request::getVar('active', 'feed'); $ajax = Request::getInt('ajax', 0); $action = Request::getVar('action', ''); $confirmcode = Request::getVar('confirm', ''); $email = Request::getVar('email', ''); $sync = false; // Stop ajax action if user got logged out if ($ajax && User::isGuest()) { // Project on hold $this->view = new \Hubzero\Component\View(array('name' => 'error', 'layout' => 'default')); $this->view->error = Lang::txt('COM_PROJECTS_PROJECT_RELOGIN'); $this->view->title = Lang::txt('COM_PROJECTS_PROJECT_RELOGIN_REQUIRED'); $this->view->display(); return; } // Check that project exists if (!$this->model->exists()) { throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404); return; } // Is this a group project? $this->group = $this->model->groupOwner(); if ($this->model->get('owned_by_group') && !$this->group) { $this->_buildPathway(); $this->_buildTitle(); // Options for project creator if ($this->model->access('owner')) { $view = new \Hubzero\Component\View(array('name' => 'changeowner', 'layout' => 'default')); $view->project = $this->model; $view->task = $this->_task; $view->option = $this->_option; $view->display(); return; } else { // Error $this->setError(Lang::txt('COM_PROJECTS_PROJECT_OWNER_DELETED')); $this->title = Lang::txt('COM_PROJECTS_PROJECT_OWNERSHIP_ERROR'); $this->_showError(); return; } } // Load acting team member $member = $this->model->member(); // Reconcile members of project groups if (!$ajax) { if ($this->model->_tblOwner->reconcileGroups($this->model->get('id'), $this->model->get('owned_by_group'))) { $sync = true; } } // Is project deleted? if ($this->model->isDeleted()) { $this->setError(Lang::txt('COM_PROJECTS_PROJECT_DELETED')); $this->introTask(); return; } // Check if project is in setup if ($this->model->inSetup() && !$ajax) { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=setup&alias=' . $this->model->get('alias'))); return; } // Sync with system group in case of changes if ($sync == true) { $this->model->_tblOwner->sysGroup($this->model->get('alias'), $this->config->get('group_prefix', 'pr-')); // Reload member $this->model->member(true); } // Set the pathway $this->_buildPathway(); // Set the page title $this->_buildTitle(); // Do we need to login? if (User::isGuest() && $action == 'login') { $this->_msg = Lang::txt('COM_PROJECTS_LOGIN_TO_VIEW_PROJECT'); $this->_login(); return; } // Determine layout to load $layout = $this->model->access('member') ? 'internal' : 'external'; $layout = $this->model->access('member') && $preview && $this->model->isPublic() ? 'external' : $layout; // Is this a provisioned project? if ($this->model->isProvisioned()) { if (!$this->_publishing) { $this->setError(Lang::txt('COM_PROJECTS_PROJECT_CANNOT_LOAD')); $this->introTask(); return; } // Redirect to publication $pub = $this->model->getPublication(); if ($pub && $pub->id) { App::redirect(Route::url('index.php?option=com_publications&task=submit&pid=' . $pub->id)); return; } else { throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404); return; } $this->view->pub = $pub; $this->view->team = $this->model->_tblOwner->getOwnerNames($this->model->get('id')); $this->view->suggested = Helpers\Html::suggestAlias($pub->title); $this->view->verified = $this->model->check($this->view->suggested, $this->model->get('id'), 0); $this->view->suggested = $this->view->verified ? $this->view->suggested : ''; } // Check if they are a reviewer $reviewer = false; if (!$this->model->access('member')) { if ($this->model->reviewerAccess('sensitive')) { $reviewer = 'sensitive'; } if ($this->model->reviewerAccess('sponsored')) { $reviewer = 'sponsored'; } } // Invitation view if ($confirmcode && (!$member or $member->status != 1)) { $match = $this->model->_tblOwner->matchInvite($this->model->get('id'), $confirmcode, $email); if (User::isGuest() && $match) { $layout = 'invited'; } elseif ($match && $this->model->_tblOwner->load($match)) { if (User::get('email') == $email) { // Confirm user $this->model->_tblOwner->status = 1; $this->model->_tblOwner->userid = User::get('id'); if (!$this->model->_tblOwner->store()) { $this->setError($this->model->_tblOwner->getError()); return false; } else { // Sync with system group $this->model->_tblOwner->sysGroup($this->model->get('alias'), $this->config->get('group_prefix', 'pr-')); // Go to project page App::redirect(Route::url($this->model->link())); return; } } else { // Error - different email $this->setError(Lang::txt('COM_PROJECTS_INVITE_DIFFERENT_EMAIL')); $this->_showError(); return; } } } // Private project if (!$this->model->isPublic() && $layout != 'invited') { // Login required if (User::isGuest()) { $this->_msg = Lang::txt('COM_PROJECTS_LOGIN_PRIVATE_PROJECT_AREA'); $this->_login(); return; } if (!$this->model->access('member') && !$reviewer) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } } // Is project suspended? if ($this->model->isInactive()) { if (!$this->model->access('member')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } $layout = 'suspended'; } // Is project pending approval? if ($this->model->isPending()) { if ($reviewer) { $layout = 'external'; } elseif (!$this->model->access('owner')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } else { $layout = 'pending'; } } // Set layout $this->view->setLayout($layout); // Record join activity if ($this->active == 'feed' && !$ajax) { // First-time visit, record join activity $this->model->recordFirstJoinActivity(); } // Get available plugins $plugins = Event::trigger('projects.onProjectAreas', array($this->model->get('alias'))); // Get tabbed plugins $this->view->tabs = Helpers\Html::getTabs($plugins); // Go through plugins $this->view->content = ''; if ($layout == 'internal') { $plugin = $this->active == 'feed' ? 'blog' : $this->active; $plugin = $this->active == 'info' ? '' : $plugin; // Get active plugins (some may not be in tabs) $activePlugins = Helpers\Html::getPluginNames($plugins); // Get plugin content if ($this->active != 'info') { // Do not go further if plugin is inactive or does not exist if (!in_array($plugin, $activePlugins)) { if ($ajax) { // Plugin not active in this project echo '<p class="error">' . Lang::txt('COM_PROJECTS_ERROR_CONTENT_CANNOT_LOAD') . '</p>'; return; } App::redirect(Route::url($this->model->link())); return; } // Plugin params $plugin_params = array($this->model, $action, array($plugin)); // Get plugin content $sections = Event::trigger('projects.onProject', $plugin_params); // Output if (!empty($sections)) { foreach ($sections as $section) { if (isset($section['html']) && $section['html']) { if ($ajax) { // AJAX output echo $section['html']; return; } else { // Normal output $this->view->content .= $section['html']; } } } } else { // No html output App::redirect(Route::url($this->model->link())); return; } } // Get item counts $counts = Event::trigger('projects.onProjectCount', array($this->model)); $this->model->set('counts', Helpers\Html::getCountArray($counts)); // Record page visit if ($this->active == 'feed' && !$ajax) { $this->model->recordVisit(); } // Hide suggestions if ($this->active == 'feed') { // Hide welcome screen? $c = Request::getInt('c', 0); if ($c) { $this->model->member()->saveParam($this->model->get('id'), User::get('id'), $param = 'hide_welcome', 1); App::redirect(Route::url($this->model->link())); return; } } } // Output HTML $this->view->params = $this->model->params; $this->view->model = $this->model; $this->view->reviewer = $reviewer; $this->view->title = $this->title; $this->view->active = $this->active; $this->view->task = $this->_task; $this->view->option = $this->_option; $this->view->config = $this->config; $this->view->msg = $this->_getNotifications('success'); if ($layout == 'invited') { $this->view->confirmcode = $confirmcode; $this->view->email = $email; } $error = $this->getError() ? $this->getError() : $this->_getNotifications('error'); if ($error) { $this->view->setError($error); } $this->view->display(); return; }