コード例 #1
0
 /**
  * Overwrite initial output value for editorial intros
  *
  * @since 0.1.0
  * @access protected
  **/
 protected function create_output()
 {
     $this->output_tag_open();
     $content = BasePattern::pattern_factory($this->input, 'paragraph', $this->element, true);
     $this->output .= $content->embed();
     $this->output_tag_close();
 }
コード例 #2
0
 public function set_block_paragraph_text()
 {
     $acf_paragraph = get_post_meta($this->container->post_id, 'block_paragraph_text', true);
     if (!empty($acf_paragraph)) {
         $input = array('text' => '<p>' . $acf_paragraph . '</p>');
         $this->container->block_paragraph_text = BasePattern::pattern_factory($input, 'paragraph', '', 'emphasisblock', false);
     }
 }
コード例 #3
0
 /**
  * Create grid item from ACF Layout
  *
  * Creates grid item with post_item data, add modifiers when necessary.
  *
  * @param integer $item Post object to be represented by grid item.
  */
 protected function create_grid_item_from_layout($item)
 {
     if (!isset($item['acf_fc_layout'])) {
         return;
     }
     $item_mods = array();
     $layout = $item['acf_fc_layout'];
     switch ($layout) {
         case 'grid_exchange_story':
         case 'grid_exchange_collaboration':
         case 'grid_exchange_programme_round':
             if (!is_numeric($item['grid_exchange_object'])) {
                 if (is_array($item['grid_exchange_object']) && is_int($item['grid_exchange_object'][0])) {
                     $object_id = $item['grid_exchange_object'][0];
                 } else {
                     return;
                 }
             } else {
                 $object_id = intval($item['grid_exchange_object']);
             }
             if (empty($object_id)) {
                 return;
             }
             $object = BaseController::exchange_factory($object_id, 'griditem');
             $item_mods = self::add_grid_modifiers($object);
             break;
         case 'grid_paragraph':
             if ('grid_paragraph' === $layout && empty($item['text'])) {
                 return;
             }
         case 'grid_pull_quote':
             if ('grid_pull_quote' === $layout && empty($item['pquote_text'])) {
                 return;
             }
         case 'grid_image':
             if ('grid_image' === $layout && empty($item['image'])) {
                 return;
             }
             $pattern_type = str_replace('grid_', '', $layout);
             $object = BasePattern::pattern_factory($item, $pattern_type, 'griditem', true);
             $item_mods['type'] = 'pattern';
             $item_mods['pattern_type'] = $pattern_type;
             break;
         default:
             return;
     }
     if (!empty($item['grid_width'])) {
         $item_mods['grid_width'] = $item['grid_width'];
         $num = $this->get_grid_width_num($item['grid_width']);
         if (isset($num) & is_int($num)) {
             $item_mods['grid_width_num'] = $num;
         }
     }
     $grid_item = new GridItem($object, $this->element, $item_mods);
     return $grid_item;
 }
コード例 #4
0
 public function publish_grid_cta($modifier = '')
 {
     $properties = array();
     if (function_exists('get_field')) {
         $properties = array('block_type' => 'cta', 'block_alignment' => false, 'cta_block_elements' => get_field('cta_block_elements', $this->post_id), 'cta_colour' => get_post_meta($this->post_id, 'cta_colour', true));
     }
     if ($modifier === 'grid_full') {
         $properties['block_alignment'] = 'full';
     }
     if (empty($properties['cta_block_elements'])) {
         return;
     } else {
         $length = count($properties['cta_block_elements']);
         for ($i = 0; $i < $length; $i++) {
             if ('block_button' === $properties['cta_block_elements'][$i]['acf_fc_layout']) {
                 // Add permalink to button if link left empty.
                 if (empty($properties['cta_block_elements'][$i]['button_link'])) {
                     $properties['cta_block_elements'][$i]['button_link'] = $this->link;
                 }
                 if (empty($properties['cta_block_elements'][$i]['button_size'])) {
                     $properties['cta_block_elements'][$i]['button_size'] = 'small';
                 }
             }
         }
     }
     $block = BasePattern::pattern_factory($properties, 'emphasis_block', 'griditem');
     echo $block;
 }
コード例 #5
0
 public function create_token_form_cta($obj, $pr_token = '', $c_obj = null)
 {
     if (empty($obj->type) && empty($obj->post_type)) {
         return;
     }
     switch ($obj->type) {
         case 'participant':
             $form_paragraph = __('Update information about you and your organisation(s)', EXCHANGE_PLUGIN);
             $cta_colour = exchange_slug_to_hex('rose-1-web');
             $form_title = !empty($obj->name) ? $obj->name : 'participant';
             // Set update link.
             $acf_update_link = $obj->get_update_form_link();
             $update_link = !empty($acf_update_link) ? $acf_update_link : '#';
             break;
         case 'collaboration':
             $form_paragraph = __('Update information on your project', EXCHANGE_PLUGIN);
             $cta_colour = exchange_slug_to_hex('blue-2-web');
             $form_title = !empty($obj->title) ? wp_trim_words($obj->title, 6, __('...', EXCHANGE_PLUGIN)) : 'collaboration';
             // Set update link.
             $acf_update_link = $obj->get_update_form_link();
             $update_link = !empty($acf_update_link) ? $acf_update_link : '#';
             break;
         default:
             if ($obj->post_type == 'page') {
                 $form_paragraph = __('Share your Tandem experience on your collaboration page', EXCHANGE_PLUGIN);
                 $cta_colour = exchange_slug_to_hex('yellow-tandem');
                 $form_title = !empty($obj->post_title) ? $obj->post_title : 'story';
                 $permalink = get_post_permalink($obj->ID);
                 if ($c_obj instanceof Collaboration && is_numeric($c_obj->post_id)) {
                     $permalink = add_query_arg('update_id', $c_obj->post_id, $permalink);
                 }
                 if (!empty($pr_token)) {
                     $permalink = add_query_arg('pr_ref', $pr_token, $permalink);
                 }
                 $update_link = !empty($permalink) ? $permalink : '#';
                 break;
             } else {
                 return;
             }
     }
     // Set paragraph.
     $paragraph = '<p>' . $form_paragraph . '</p>';
     // Set programme name for logo.
     $prog_name = explode(' ', $this->title)[1];
     if (in_array($prog_name, array('C&P', 'Community', 'C'), true)) {
         $prog_name = 'C_P';
     }
     $properties = array('block_type' => 'cta', 'cta_colour' => $cta_colour, 'block_alignment' => false, 'cta_block_elements' => array(0 => array('acf_fc_layout' => 'block_header', 'block_header_text' => $form_title), 1 => array('acf_fc_layout' => 'block_logo', 'block_programme' => $prog_name), 2 => array('acf_fc_layout' => 'block_paragraph', 'block_paragraph_text' => $form_paragraph)));
     if ('collaboration' === $obj->type) {
         if (isset($obj->link)) {
             $properties['cta_block_elements'][3] = array('acf_fc_layout' => 'block_button', 'button_size' => 'small', 'button_text' => __('View my collaboration', EXCHANGE_PLUGIN), 'button_help_text' => __('Navigate to your collaboration page', EXCHANGE_PLUGIN), 'button_link' => $obj->link, 'button_target' => '_self');
         }
         if (isset($form_title) && isset($update_link)) {
             $properties['cta_block_elements'][4] = array('acf_fc_layout' => 'block_button', 'button_size' => 'small', 'button_text' => __('Update my collaboration page', EXCHANGE_PLUGIN), 'button_help_text' => sprintf(__('Add or edit information for %s', EXCHANGE_PLUGIN), $form_title), 'button_link' => $update_link, 'button_target' => '_self');
         }
     } elseif ('participant' === $obj->type) {
         if (isset($form_title) && isset($update_link)) {
             $properties['cta_block_elements'][3] = array('acf_fc_layout' => 'block_button', 'button_size' => 'small', 'button_text' => __('Update my info', EXCHANGE_PLUGIN), 'button_help_text' => sprintf(__('Edit the information about %s', EXCHANGE_PLUGIN), $form_title), 'button_link' => $update_link, 'button_target' => '_self');
         }
     } elseif ('page' === $obj->post_type) {
         $properties['cta_block_elements'][3] = array('acf_fc_layout' => 'block_button', 'button_size' => 'small', 'button_text' => __('Submit a story', EXCHANGE_PLUGIN), 'button_help_text' => __('Navigate to the page for submitting stories', EXCHANGE_PLUGIN), 'button_link' => $update_link, 'button_target' => '_self');
     }
     // $results = '<pre>' . print_r( $properties, true ) . '</pre>';
     // return $results;
     $block = BasePattern::pattern_factory($properties, 'emphasis_block', 'griditem', true);
     $griditem_mods = array('grid_width' => 'grid_fourth', 'type' => 'cta', 'grid_width_num' => 3);
     $griditem = new Griditem($block, 'simplegrid', $griditem_mods);
     return $griditem;
 }
コード例 #6
0
 public function publish_collab_files($context = '')
 {
     if (!$this->has_files) {
         return;
     }
     $doc_block_input = array('add_file' => array());
     foreach ($this->files as $file) {
         $doc_block_input['add_file'][] = array('file' => $file);
     }
     $doc_block = BasePattern::pattern_factory($doc_block_input, 'uploaded_files', 'collaboration', true);
     if ($doc_block instanceof Documentblock) {
         $grid_mods = array('type' => 'documentblock');
         $griditem = new GridItem($doc_block, 'collaboration', $grid_mods);
         $griditem->publish();
     }
 }