Example #1
0
 public static function renderWidget($params)
 {
     $widget = WidgetTable::getInstance()->fetch($params[1]);
     if (!$widget || $widget->getStatus() != Widget::STATUS_ACTIVE) {
         return '';
     }
     $context = sfContext::getInstance();
     $petition = $widget->getPetition();
     $url = $context->getRouting()->generate('sign_hp', array('id' => $widget['id'], 'hash' => $widget->getLastHash(true)), true);
     $count = $petition->getCount(60);
     $target = $count . '-' . Petition::calcTarget($count, $petition->getTargetNum());
     $widget_id = $widget['id'];
     $stylings = json_decode($widget->getStylings(), true);
     $stylings['type'] = 'embed';
     $stylings['url'] = $url;
     $stylings['width'] = 'auto';
     $stylings['count'] = number_format($count, 0, '.', ',') . ' ' . 'people so far';
     $stylings['target'] = $target;
     return '<script type="text/javascript">' . self::getInitJS() . self::getAddStyleJS($widget_id, $stylings) . self::getWidgetHereJs($widget_id, false) . '</script>';
 }
 public function executeWidgetOuter(sfWebRequest $request)
 {
     $this->fetchWidget();
     $petition = $this->widget['Petition'];
     /* @var $petition Petition */
     $petition_text = $this->widget['PetitionText'];
     /* @var $petition_text PetitionText */
     $this->count = $petition->getCount(60);
     $this->target = $this->count . '-' . Petition::calcTarget($this->count, $this->widget->getPetition()->getTargetNum());
     $image_prefix = ($request->isSecure() ? 'https://' : 'http://') . $request->getHost() . '/' . $request->getRelativeUrlRoot() . 'images/';
     $this->kind = $this->widget->getPetition()->getKind();
     $this->lang = $this->widget->getPetitionText()->getLanguageId();
     $this->getUser()->setCulture($this->lang);
     $this->label_mode = $this->widget->getPetition()->getLabelMode();
     $stylings = json_decode($this->widget->getStylings(), true);
     if (!is_array($stylings)) {
         $stylings = array();
     }
     $widget_colors = $petition->getWidgetIndividualiseDesign();
     foreach (array('title_color', 'body_color', 'button_color', 'bg_left_color', 'bg_right_color', 'form_title_color') as $style) {
         if (!$widget_colors || !isset($stylings[$style]) || !$stylings[$style]) {
             $stylings[$style] = $petition['style_' . $style];
         }
     }
     $this->stylings = $stylings;
     $this->keyvisual = $this->widget->getPetition()->getKeyVisual() ? $image_prefix . 'keyvisual/' . $this->widget->getPetition()->getKeyVisual() : null;
     $this->sprite = $image_prefix . 'policat.spr.png';
     $this->url = $this->getContext()->getRouting()->generate('sign', array('id' => $this->widget['id'], 'hash' => $this->widget->getLastHash(true)), true);
     $this->getResponse()->setContentType('text/javascript');
     $this->setLayout(false);
     $title = $this->widget->getTitle();
     if (!$petition->getWidgetIndividualiseText()) {
         $title = $petition_text->getTitle();
     }
     $this->title = Util::enc($title);
 }
 public function executeCounterbar(sfWebRequest $request)
 {
     $widget = Doctrine_Core::getTable('Widget')->find($request->getParameter('id'));
     /* @var $widget Widget */
     $this->count = $widget->getPetition()->getCount(60);
     $this->target = Petition::calcTarget($this->count, $widget->getPetition()->getTargetNum());
     $this->lang = $widget->getPetitionText()->getLanguageId();
     $this->getUser()->setCulture($this->lang);
     $this->stylings = json_decode($widget->getStylings(), true);
     $this->widgetid = $widget->getId();
     $this->markup = $this->getPartial('counterbar', array('count' => $this->count, 'target' => $this->target, 'stylings' => $this->stylings, 'widgetid' => $this->widgetid));
     $this->getResponse()->setContentType('text/javascript');
     $this->setLayout(false);
 }
 public function executeFeature()
 {
     $title = trim(StoreTable::value(StoreTable::PORTAL_HOME_TITLE, ''));
     $this->title = $title ? $title : 'Featured action';
     $markup = trim(StoreTable::value(StoreTable::PORTAL_HOME_MARKUP, ''));
     if ($markup) {
         $markup = preg_replace_callback('/#KEYVISUAL-(\\d+)#/', array($this, 'getKeyvisualUrl'), $markup);
         $markup = preg_replace('/#WIDGET-(\\d+)#/', 'PasjhkX\\1KmsownedS', $markup);
         // prevent markdown messing up widget
         $markup = UtilMarkdown::transform($markup, true, true);
         $this->markup = preg_replace_callback('/PasjhkX(\\d+)KmsownedS/', array('UtilWidget', 'renderWidget'), $markup);
         return;
     }
     $id = PetitionTable::getInstance()->createQuery('p')->where('p.status = ?', Petition::STATUS_ACTIVE)->andWhere('p.homepage = 1')->leftJoin('p.Campaign c')->andWhere('c.status = ?', CampaignTable::STATUS_ACTIVE)->leftJoin('p.PetitionText pt')->andWhere('pt.status = ?', PetitionText::STATUS_ACTIVE)->andWhere('pt.language_id = ?', 'en')->leftJoin('pt.DefaultWidget w')->andWhere('w.status = ?', Widget::STATUS_ACTIVE)->select('p.id')->addSelect('(SELECT count(z.id) FROM PetitionSigning z WHERE DATE_SUB(NOW(),INTERVAL 1 DAY) <= z.created_at  and z.petition_id = p.id and z.status = ' . PetitionSigning::STATUS_VERIFIED . ') as signings24')->limit(1)->orderBy('signings24 DESC, p.id ASC')->fetchArray();
     if ($id) {
         $id = $id[0]['id'];
         $petition = PetitionTable::getInstance()->createQuery('p')->where('p.id = ?', $id)->andWhere('p.status = ?', Petition::STATUS_ACTIVE)->andWhere('p.homepage = 1')->leftJoin('p.Campaign c')->andWhere('c.status = ?', CampaignTable::STATUS_ACTIVE)->leftJoin('p.PetitionText pt')->andWhere('pt.status = ?', PetitionText::STATUS_ACTIVE)->andWhere('pt.language_id = ?', 'en')->leftJoin('pt.DefaultWidget w')->andWhere('w.status = ?', Widget::STATUS_ACTIVE)->select('p.name, p.object_version, p.kind, p.language_id, p.twitter_tags, p.key_visual, p.read_more_url, pt.id, pt.object_version, pt.title, pt.target, pt.body, pt.footer, pt.email_subject, pt.email_body, w.id, w.object_version, w.title, w.target, w.intro, w.footer, w.email_subject, w.email_body, w.stylings')->fetchOne();
         if ($petition) {
             /* @var $petition Petition */
             $text = $petition['PetitionText'][0];
             $widget = $text['DefaultWidget'];
             $url = $this->generateUrl('sign_hp', array('id' => $widget['id'], 'hash' => $widget->getLastHash(true)), true);
             $this->count = $petition->getCount(60);
             $this->target = $this->count . '-' . Petition::calcTarget($this->count, $petition->getTargetNum());
             $this->widget_id = $widget['id'];
             $this->stylings = json_decode($widget->getStylings(), true);
             $this->stylings['type'] = 'embed';
             $this->stylings['url'] = $url;
             $this->stylings['width'] = 'auto';
         }
     }
 }