/**
  * Validates that the revised contents are valid JSON.
  * If not valid, rejects edit with error message.
  * @param EditPage $editor
  * @param string $text Content of the revised article.
  * @param string &$error Error message to return.
  * @param string $summary Edit summary provided for edit.
  * @return True
  */
 static function onEditFilterMerged($editor, $text, &$error, $summary)
 {
     if (!$editor->getTitle()->inNamespace(NS_CAMPAIGN)) {
         return true;
     }
     $content = new CampaignContent($text);
     try {
         $content->validate();
     } catch (JsonSchemaException $e) {
         $error = $e->getMessage();
     }
     return true;
 }
Beispiel #2
0
 /**
  * before a campaign is saved we need to create content and translate the form
  * values for the lists and segments into multi dimensional arrays for the soap
  * call
  * @return boolean
  */
 public function before_save()
 {
     if (!is_string($this->primval())) {
         //new campaign content
         $content = new CampaignContent();
         $content->title = $this->CampaignName;
         $content->subject = $this->CampaignSubject;
         $content->content = $this->content;
         //if this saves ok then create joins and setup arrays for soap
         if ($res = $content->save()) {
             $this->CampaignID = false;
             $data = Request::param('campaign');
             if (!is_array($data)) {
                 $data = $this->row;
             }
             //if no post data use the rowset of this model
             if ($data['content_list']) {
                 //join all the articles to the campaign_content
                 if (!is_array($data['content_list'])) {
                     $articles = array(0 => $data['content_list']);
                 } else {
                     $articles = $data['content_list'];
                 }
                 foreach ($articles as $story_id) {
                     $cont = new CmsContent($story_id);
                     $res->articles = $cont;
                 }
             }
             if ($this->lists = $data['lists']) {
                 //if listIds have been passed then create an array based on them
                 if (!is_array($this->lists)) {
                     $this->SubscriberListIDs = array('string' => array($this->lists));
                 } else {
                     $lists = array();
                     foreach ($this->lists as $list) {
                         $lists[] = $list;
                     }
                     $this->SubscriberListIDs = array('string' => $lists);
                 }
             } elseif ($this->segments = $data['segments']) {
                 //if segments are to be used then make complex array structure
                 if (!is_array($this->segments)) {
                     $exp = explode('~', $this->segments);
                     $this->ListSegments = array('List' => array(array('ListID' => $exp[0], 'Name' => $exp[1])));
                 } else {
                     $segs = array();
                     foreach ($this->segments as $seg) {
                         $exp = explode('~', $seg);
                         $segs[] = array('ListID' => $exp[0], 'Name' => $exp[1]);
                     }
                     $this->ListSegments = array('List' => $segs);
                 }
             }
             //set the urls for this email
             if (!$this->HtmlUrl) {
                 $this->HtmlUrl = $this->TextUrl = "http://" . $_SERVER['HTTP_HOST'] . "/emailcontent/" . $res->id;
             }
             if (!$this->TextUrl) {
                 $this->TextUrl .= ".txt";
             }
             return true;
         } else {
             return false;
         }
     } else {
         return true;
     }
 }