예제 #1
0
 public function dispatch($action)
 {
     // Notify helpers of action preDispatch state
     $this->_helper->notifyPreDispatch();
     $this->preDispatch();
     Kwf_Benchmark::checkpoint('Action::preDispatch');
     if ($this->getRequest()->isDispatched()) {
         if (null === $this->_classMethods) {
             $this->_classMethods = get_class_methods($this);
         }
         // preDispatch() didn't change the action, so we can continue
         if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) {
             if ($this->getInvokeArg('useCaseSensitiveActions')) {
                 trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"');
             }
             $this->{$action}();
         } else {
             $this->__call($action, array());
         }
         Kwf_Benchmark::checkpoint('Action::action');
         $this->postDispatch();
         Kwf_Benchmark::checkpoint('Action::postDispatch');
     }
     // whats actually important here is that this action controller is
     // shutting down, regardless of dispatching; notify the helpers of this
     // state
     $this->_helper->notifyPostDispatch();
 }
예제 #2
0
 public function renderMaster($component)
 {
     static $benchmarkEnabled;
     if (!isset($benchmarkEnabled)) {
         $benchmarkEnabled = Kwf_Benchmark::isEnabled();
     }
     $content = false;
     if ($this->_enableCache) {
         $content = Kwf_Component_Cache::getInstance()->load($component->componentId, $this->_getRendererName(), 'fullPage');
         $this->_minLifetime = null;
     }
     Kwf_Benchmark::checkpoint('load fullPage cache');
     $statType = null;
     if (!$content) {
         if ($benchmarkEnabled) {
             $startTime = microtime(true);
         }
         if (!$this->_enableCache || ($content = Kwf_Component_Cache::getInstance()->load($component, $this->_getRendererName(), 'page')) === null) {
             $masterHelper = new Kwf_Component_View_Helper_Master();
             $masterHelper->setRenderer($this);
             $content = $masterHelper->master($component);
             if ($this->_enableCache) {
                 Kwf_Component_Cache::getInstance()->save($component, $content, $this->_getRendererName(), 'page', '', '', null);
                 $statType = 'miss';
             } else {
                 $statType = 'noviewcache';
             }
         } else {
             $statType = 'hit';
         }
         if ($statType) {
             Kwf_Benchmark::count("rendered {$statType}", $component->componentId . ': page');
         }
         Kwf_Benchmark::countLog('render-' . $statType);
         if ($benchmarkEnabled) {
             Kwf_Benchmark::subCheckpoint($component->componentId . ' page', microtime(true) - $startTime);
         }
         Kwf_Benchmark::checkpoint('render page');
         $pass1Cacheable = true;
         $content = $this->_renderPass1($content, $pass1Cacheable);
         Kwf_Benchmark::checkpoint('render pass 1');
         if ($this->_enableCache && $pass1Cacheable) {
             Kwf_Component_Cache::getInstance()->save($component, $content, $this->_getRendererName(), 'fullPage', '', '', $this->_minLifetime);
         }
         Kwf_Benchmark::count("rendered miss", $component->componentId . ': fullPage');
         Kwf_Benchmark::countLog('fullpage-miss');
     } else {
         Kwf_Benchmark::count("rendered hit", $component->componentId . ': fullPage');
         Kwf_Benchmark::countLog('fullpage-hit');
     }
     $content = $this->_renderPass2($content);
     Kwf_Benchmark::checkpoint('render pass 2');
     Kwf_Component_Cache::getInstance()->writeBuffer();
     return $content;
 }
 public function sendAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     Kwf_Events_ModelObserver::getInstance()->disable();
     $newsletterId = $this->_getParam('newsletterId');
     $nlRow = Kwf_Model_Abstract::getInstance('Kwc_Newsletter_Model')->getRow($newsletterId);
     $mailsPerMinute = $nlRow->getCountOfMailsPerMinute();
     // In Schleife senden
     $queueLogModel = $nlRow->getModel()->getDependentModel('QueueLog');
     $count = 0;
     $countErrors = 0;
     $countNoUser = 0;
     $start = microtime(true);
     do {
         // Schlafen bis errechnet Zeit
         if ($nlRow->mails_per_minute != 'unlimited') {
             $sleep = $start + 60 / $mailsPerMinute * $count - microtime(true);
             if ($sleep > 0) {
                 usleep($sleep * 1000000);
             }
             if ($this->_getParam('debug')) {
                 echo "sleeping {$sleep}s\n";
             }
         }
         $nlStatus = Kwf_Model_Abstract::getInstance('Kwc_Newsletter_Model')->fetchColumnByPrimaryId('status', $nlRow->id);
         if ($nlStatus != 'sending') {
             if ($this->_getParam('debug')) {
                 echo "break sending because newsletter status changed to '{$nlStatus}'\n";
             }
             break;
         }
         Kwf_Benchmark::enable();
         Kwf_Benchmark::reset();
         Kwf_Benchmark::checkpoint('start');
         $userStart = microtime(true);
         // Zeile aus queue holen, falls nichts gefunden, Newsletter fertig
         $row = $nlRow->getNextQueueRow(getmypid());
         Kwf_Benchmark::checkpoint('get next recipient');
         if ($row) {
             $recipient = $row->getRecipient();
             if (!$recipient || !$recipient->getMailEmail()) {
                 $countNoUser++;
                 $status = 'usernotfound';
             } else {
                 if ($recipient instanceof Kwc_Mail_Recipient_UnsubscribableInterface && $recipient->getMailUnsubscribe()) {
                     $countNoUser++;
                     $status = 'usernotfound';
                 } else {
                     if ($recipient instanceof Kwf_Model_Row_Abstract && $recipient->hasColumn('activated') && !$recipient->activated) {
                         $countNoUser++;
                         $status = 'usernotfound';
                     } else {
                         try {
                             $mc = $nlRow->getMailComponent();
                             $t = microtime(true);
                             $mail = $mc->createMail($recipient);
                             $createTime = microtime(true) - $t;
                             $t = microtime(true);
                             $mail->send();
                             $sendTime = microtime(true) - $t;
                             Kwf_Benchmark::checkpoint('send mail');
                             $count++;
                             $status = 'sent';
                         } catch (Exception $e) {
                             echo 'Exception in Sending Newsletter with id ' . $nlRow->id . ' with recipient ' . $recipient->getMailEmail();
                             echo $e->__toString();
                             $countErrors++;
                             $status = 'failed';
                         }
                         $nlRow->getModel()->getTable()->update(array('count_sent' => new Zend_Db_Expr('count_sent + 1'), 'last_sent_date' => date('Y-m-d H:i:s')), 'id = ' . $nlRow->id);
                     }
                 }
             }
             $queueLogModel->createRow(array('newsletter_id' => $row->newsletter_id, 'recipient_model' => $row->recipient_model, 'recipient_id' => $row->recipient_id, 'status' => $status, 'send_date' => date('Y-m-d H:i:s')))->save();
             $row->delete();
             Kwf_Benchmark::checkpoint('update queue');
             if ($this->_getParam('verbose')) {
                 if (Kwf_Benchmark::isEnabled() && $this->_getParam('benchmark')) {
                     echo Kwf_Benchmark::getCheckpointOutput();
                 }
                 echo "[" . getmypid() . "] {$status} in " . round((microtime(true) - $userStart) * 1000) . "ms (";
                 echo "create " . round($createTime * 1000) . "ms, ";
                 echo "send " . round($sendTime * 1000) . "ms";
                 echo ") [" . round(memory_get_usage() / (1024 * 1024)) . "MB] [" . round($count / (microtime(true) - $start), 1) . " mails/s]\n";
             }
             if ($status == 'failed' && $this->_getParam('debug')) {
                 echo "stopping because sending failed in debug mode\n";
                 break;
             }
             if (memory_get_usage() > 100 * 1024 * 1024) {
                 if ($this->_getParam('debug')) {
                     echo "stopping because of >100MB memory usage\n";
                 }
                 break;
             }
         }
     } while ($row);
     $stop = microtime(true);
     // Log schreiben
     $logModel = $nlRow->getModel()->getDependentModel('Log');
     $row = $logModel->createRow(array('newsletter_id' => $nlRow->id, 'start' => date('Y-m-d H:i:s', floor($start)), 'stop' => date('Y-m-d H:i:s', floor($stop)), 'count' => $count, 'countErrors' => $countErrors));
     $row->save();
     // Debugmeldungen
     if ($this->_getParam('debug')) {
         $average = round($count / ($stop - $start) * 60);
         $info = $nlRow->getInfo();
         echo "\n";
         echo "{$count} Newsletters sent ({$average}/minute), {$countErrors} errors, {$countNoUser} user not found.\n";
         echo $info['text'] . "\n";
     }
     Kwf_Events_ModelObserver::getInstance()->enable();
 }
예제 #4
0
 public function sendContent($includeMaster)
 {
     $benchmarkEnabled = Kwf_Benchmark::isEnabled();
     if (Kwf_Util_Https::supportsHttps()) {
         $foundRequestHttps = Kwf_Util_Https::doesComponentRequestHttps($this->_data);
         if (isset($_SERVER['HTTPS'])) {
             //we are on https
             if (!$foundRequestHttps && isset($_COOKIE['kwcAutoHttps']) && !Zend_Session::sessionExists() && !Zend_Session::isStarted()) {
                 //we where auto-redirected to https but don't need https anymore
                 setcookie('kwcAutoHttps', '', 0, '/');
                 //delete cookie
                 Kwf_Util_Https::ensureHttp();
             }
         } else {
             //we are on http
             if ($foundRequestHttps) {
                 setcookie('kwcAutoHttps', '1', 0, '/');
                 Kwf_Util_Https::ensureHttps();
             }
         }
         if ($benchmarkEnabled) {
             Kwf_Benchmark::checkpoint('check requestHttps');
         }
     }
     if ($benchmarkEnabled) {
         $startTime = microtime(true);
     }
     $process = $this->_getProcessInputComponents($includeMaster);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::subCheckpoint('getProcessInputComponents', microtime(true) - $startTime);
     }
     self::_callProcessInput($process);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('processInput');
     }
     $hasDynamicParts = false;
     $out = $this->_render($includeMaster, $hasDynamicParts);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('render');
     }
     header('Content-Type: text/html; charset=utf-8');
     if (!$hasDynamicParts) {
         $lifetime = 60 * 60;
         header('Cache-Control: public, max-age=' . $lifetime);
         header('Expires: ' . gmdate("D, d M Y H:i:s \\G\\M\\T", time() + $lifetime));
         header('Pragma: public');
     }
     echo $out;
     self::_callPostProcessInput($process);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('postProcessInput');
     }
 }
예제 #5
0
 public static function dispatchKwc()
 {
     $requestPath = self::getRequestPath();
     if ($requestPath === false) {
         return;
     }
     $fullRequestPath = $requestPath;
     $data = null;
     $baseUrl = Kwf_Setup::getBaseUrl();
     if ($baseUrl) {
         if (substr($requestPath, 0, strlen($baseUrl)) != $baseUrl) {
             throw new Kwf_Exception_NotFound();
         }
         $requestPath = substr($requestPath, strlen($baseUrl));
     }
     $uri = substr($requestPath, 1);
     $i = strpos($uri, '/');
     if ($i) {
         $uri = substr($uri, 0, $i);
     }
     if ($uri == 'robots.txt') {
         Kwf_Util_RobotsTxt::output();
     }
     if ($uri == 'sitemap.xml') {
         $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl('http://' . $_SERVER['HTTP_HOST'] . Kwf_Setup::getBaseUrl() . '/', null);
         Kwf_Component_Sitemap::output($data->getDomainComponent());
     }
     if (!in_array($uri, array('media', 'kwf', 'admin', 'assets', 'vkwf', 'api'))) {
         if (!isset($_SERVER['HTTP_HOST'])) {
             $requestUrl = 'http://' . Kwf_Config::getValue('server.domain') . $fullRequestPath;
         } else {
             $requestUrl = 'http://' . $_SERVER['HTTP_HOST'] . $fullRequestPath;
         }
         Kwf_Trl::getInstance()->setUseUserLanguage(false);
         $root = Kwf_Component_Data_Root::getInstance();
         foreach ($root->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $p) {
             $p->preDispatch($requestUrl);
         }
         $acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
         $exactMatch = true;
         $data = $root->getPageByUrl($requestUrl, $acceptLanguage, $exactMatch);
         Kwf_Benchmark::checkpoint('getPageByUrl');
         if (!$data) {
             throw new Kwf_Exception_NotFound();
         }
         if (!$exactMatch) {
             if (rawurldecode($data->url) == $fullRequestPath) {
                 throw new Kwf_Exception("getPageByUrl reported this isn't an exact match, but the urls are equal. wtf.");
             }
             $url = $data->url;
             if (!$url) {
                 // e.g. firstChildPageData without child pages
                 throw new Kwf_Exception_NotFound();
             }
             foreach ($root->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $p) {
                 $url = $p->processUrl($url);
             }
             if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) {
                 $url .= '?' . $_SERVER['QUERY_STRING'];
             }
             header('Location: ' . $url, true, 301);
             exit;
         }
         $root->setCurrentPage($data);
         Kwf_User_Autologin::processCookies();
         $contentSender = Kwf_Component_Settings::getSetting($data->componentClass, 'contentSender');
         $contentSender = new $contentSender($data);
         $contentSender->sendContent(true);
         Kwf_Benchmark::shutDown();
         //TODO: ein flag oder sowas ähnliches stattdessen verwenden
         if ($data instanceof Kwc_Abstract_Feed_Component || $data instanceof Kwc_Export_Xml_Component || $data instanceof Kwc_Export_Xml_Trl_Component) {
             echo "<!--";
         }
         Kwf_Benchmark::output();
         if ($data instanceof Kwc_Abstract_Feed_Component || $data instanceof Kwc_Export_Xml_Component || $data instanceof Kwc_Export_Xml_Trl_Component) {
             echo "-->";
         }
         exit;
     } else {
         if ($requestPath == '/kwf/util/kwc/render') {
             Kwf_User_Autologin::processCookies();
             Kwf_Util_Component::dispatchRender();
         }
     }
 }
예제 #6
0
 public function sendContent($includeMaster)
 {
     $benchmarkEnabled = Kwf_Benchmark::isEnabled();
     if ($benchmarkEnabled) {
         $startTime = microtime(true);
     }
     $process = $this->_getProcessInputComponents($includeMaster);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::subCheckpoint('getProcessInputComponents', microtime(true) - $startTime);
     }
     self::_callProcessInput($process);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('processInput');
     }
     $hasDynamicParts = false;
     $out = $this->_render($includeMaster, $hasDynamicParts);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('render');
     }
     header('Content-Type: text/html; charset=utf-8');
     if (!$hasDynamicParts) {
         $lifetime = 60 * 60;
         header('Cache-Control: public, max-age=' . $lifetime);
         header('Expires: ' . gmdate("D, d M Y H:i:s \\G\\M\\T", time() + $lifetime));
         header('Pragma: public');
     }
     echo $out;
     self::_callPostProcessInput($process);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('postProcessInput');
     }
 }
예제 #7
0
 public static final function shutDown()
 {
     static $wasCalled = false;
     if ($wasCalled) {
         return;
     }
     $wasCalled = true;
     Kwf_Benchmark::checkpoint('shutDown');
     if (!self::$_logEnabled) {
         return;
     }
     self::_getInstance()->_shutDown();
 }
예제 #8
0
 public function renderComponent($component, &$hasDynamicParts = false)
 {
     static $benchmarkEnabled;
     if (!isset($benchmarkEnabled)) {
         $benchmarkEnabled = Kwf_Benchmark::isEnabled();
     }
     $content = false;
     if ($this->_enableCache && $component->isPage) {
         //use fullPage cache only for pages
         $content = Kwf_Component_Cache::getInstance()->load($component->componentId, $this->_getRendererName(), 'fullPage');
         $this->_minLifetime = null;
     }
     Kwf_Benchmark::checkpoint('load fullPage cache');
     $statType = null;
     if (!$content) {
         $helper = new Kwf_Component_View_Helper_Component();
         $helper->setRenderer($this);
         $content = $helper->component($component);
         $pass1Cacheable = true;
         $content = $this->_renderPass1($content, $pass1Cacheable);
         Kwf_Benchmark::checkpoint('render pass 1');
         if (strpos($content, '<kwc2 ') === false) {
             //if there are no components that need second render cycle start HtmlParser now
             //and cache result in fullPage cache
             if ($this->_renderFormat == self::RENDER_HTML && $this->_htmlStyles) {
                 $p = new Kwc_Mail_HtmlParser($this->_htmlStyles);
                 $content = $p->parse($content);
                 Kwf_Benchmark::checkpoint('html parser (in fullPage)');
             }
         }
         if ($this->_enableCache && $pass1Cacheable && $component->isPage) {
             Kwf_Component_Cache::getInstance()->save($component, $content, $this->_getRendererName(), 'fullPage', '', '', $this->_minLifetime);
         }
     }
     $hasPass2Placeholders = strpos($content, '<kwc2 ') !== false;
     $content = $this->_renderPass2($content);
     Kwf_Benchmark::checkpoint('render pass 2');
     //if there where components that needed second render cycle the HtmlParser wasn't started yet
     //do that now (should be avoided as it's slow)
     if ((!$component->isPage || $hasPass2Placeholders) && $this->_renderFormat == self::RENDER_HTML && $this->_htmlStyles) {
         $p = new Kwc_Mail_HtmlParser($this->_htmlStyles);
         $content = $p->parse($content);
         Kwf_Benchmark::checkpoint('html parser');
     }
     Kwf_Component_Cache::getInstance()->writeBuffer();
     return $content;
 }
예제 #9
0
 /**
  * Gibt den personalisierten Quelltext der Mail zurück
  *
  * @see getHtml Für Ersetzungen siehe
  */
 public function getText(Kwc_Mail_Recipient_Interface $recipient = null)
 {
     $renderer = new Kwf_Component_Renderer_Mail();
     $renderer->setRenderFormat(Kwf_Component_Renderer_Mail::RENDER_TXT);
     $renderer->setRecipient($recipient);
     $ret = $renderer->renderComponent($this->getData());
     Kwf_Benchmark::checkpoint('text: render');
     $ret = $this->_processPlaceholder($ret, $recipient);
     Kwf_Benchmark::checkpoint('text: placeholder');
     $ret = str_replace('&nbsp;', ' ', $ret);
     $redirect = $this->getData()->getChildComponent('_redirect');
     if ($redirect) {
         $ret = $redirect->getComponent()->replaceLinks($ret, $recipient);
     }
     Kwf_Benchmark::checkpoint('text: replaceLinks');
     return $ret;
 }
예제 #10
0
 public function getContent($includeMaster)
 {
     if ($this->_data->getBaseProperty('preLogin')) {
         $ignore = false;
         foreach (Kwf_Config::getValueArray('preLoginIgnoreIp') as $i) {
             $ip = $_SERVER['REMOTE_ADDR'];
             if ($ip == $i) {
                 $ignore = true;
             }
             if (!$ignore && substr($i, -1) == '*') {
                 $i = substr($i, 0, -1);
                 if (substr($ip, 0, strlen($i)) == $i) {
                     $ignore = true;
                 }
             }
             if (!$ignore && substr($i, 0, 1) == '*') {
                 $i = substr($i, 1);
                 if (substr($ip, -strlen($i)) == $i) {
                     $ignore = true;
                 }
             }
         }
         Kwf_Setup::checkPreLogin($this->_data->getBaseProperty('preLoginUser'), $this->_data->getBaseProperty('preLoginPassword'));
     }
     $benchmarkEnabled = Kwf_Benchmark::isEnabled();
     if ($benchmarkEnabled) {
         $startTime = microtime(true);
     }
     $process = $this->_getProcessInputComponents($includeMaster);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::subCheckpoint('getProcessInputComponents', microtime(true) - $startTime);
     }
     self::_callProcessInput($process);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('processInput');
     }
     $ret = array();
     $hasDynamicParts = false;
     $ret['content'] = $this->_render($includeMaster, $hasDynamicParts);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('render');
     }
     $ret['mimeType'] = 'text/html; charset=utf-8';
     if (!$includeMaster) {
         $assetsBox = $this->_data->getChildComponent('-assets');
         if ($assetsBox) {
             $ret['assets'] = $assetsBox->render(null, false, $hasDynamicParts);
         } else {
             $ret['assets'] = '';
         }
     }
     if (!$hasDynamicParts) {
         $ret['lifetime'] = 60 * 60;
     }
     self::_callPostProcessInput($process);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('postProcessInput');
     }
     return $ret;
 }