PluginProbe
Social Share Buttons / 1.2
Social Share Buttons v1.2
trunk 0.9 1.0 1.1 1.1.1 1.1.2 1.10 1.11 1.12 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.3 1.30 1.4 1.5 1.6 1.7 1.8 1.9
share-button / classes / class-collection.php

class-collection.php in Social Share Buttons 1.2, at classes/class-collection.php

1,030 lines 24.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MBSocial;
3 defined('ABSPATH') or die('No direct access permitted');
4
5 use \maxbuttons\maxUtils as maxUtils;
6 use \maxbuttons\maxCSSParser as maxCSSParser;
7 use \simple_html_dom as simple_html_dom;
8
9
10 class collection
11 {
12 protected $blocks = array(); // array of objects
13 protected $buttons = array();
14 protected $data; // data of the collection
15 protected $meta_data; // data stored specific to posts / pages etc
16
17 protected $css;
18
19 protected $collection_id = 0;
20 protected static $count = 0;
21 protected $collection_type = 'social_share';
22 protected $styleObj = null;
23
24 // layout functions
25 protected $cssParser;
26
27 // save hook currently active
28 protected $doingHook;
29
30 public $is_showable = true; // keeps state of hidden options
31 public $is_static = false;
32 public $is_post = false; // embedded in a post situation
33 public $is_mobile = false;
34 public $is_tablet = false;
35 public $orientation = 'horizontal';
36 public $display_mode = 'hidden';
37 public $post_id;
38
39
40 /* Constructor
41 Sets the blocks used in this collection. These are mostly derived from subclasses of the specific collection types.
42 */
43 public function __construct($collection_id = 0)
44 {
45 collections::checkExpireTrans();
46 $w = MBSocial()->whistle();
47 $w->tell('collection/new', $collection_id);
48 self::$count++;
49
50 $blocks = collections::getBlocks();
51
52 $default_data = array();
53
54
55 foreach($blocks as $block_name)
56 {
57 $block = collections::getBlock($block_name);
58 if ($block)
59 {
60 $block->setCollection($this);
61 $default_data = $block->save_fields($default_data, null ); // force the fields to set a default pos.
62
63 $this->blocks[$block_name] = $block;
64
65 }
66 }
67
68 // then load the default as data
69 $this->data = $default_data;
70
71 foreach($this->blocks as $block)
72 {
73 if ($block)
74 {
75 $block->set($default_data);
76 }
77
78 }
79
80 if ($collection_id > 0)
81 {
82 $this->set($collection_id);
83 }
84 }
85 /* Get all buttons that are currently loaded */
86 /*public function getLoadedButtons()
87 {
88 return $this->buttons;
89 } */
90
91
92
93
94 /* Get a certain block class by name */
95 public function getBlock($blockname)
96 {
97
98 if (isset($this->blocks[$blockname]))
99 return $this->blocks[$blockname];
100 else
101 return false;
102 }
103
104 /* Get the type of the collection */
105 /*public function getType()
106 {
107 return $this->collection_type;
108 } */
109
110 /* Get the ID of the collection */
111 public function getID()
112 {
113 return $this->collection_id;
114 }
115
116 /** Get the MaxCSSParser classes which handles SCSS. This function is derived from the one in Button class */
117 public function getCSSParser()
118 {
119 if (! $this->cssParser)
120 { $this->cssParser = new maxCSSParser();
121 $this->cssParser->anchor_class = '.mb-social';
122 }
123 return $this->cssParser;
124 }
125
126 /** Set the collection by ID
127 * @param $collection_id ID of the collection stored in database
128 */
129 public function set($collection_id)
130 {
131 $this->collection_id = $collection_id;
132
133
134 // make every block set it's stuff.
135 $data = $this->get_meta();
136 if ( isset($data['style']['style']) )
137 {
138 Install::convertToOne($this);
139 $data = $this->get_meta();
140 }
141
142 foreach($this->blocks as $name => $block)
143 {
144 // run every blocks setter
145 $block->set($data);
146 }
147
148 $this->data = $data;
149 }
150
151 public function setData($blockname, $data)
152 {
153 if (! isset($this->data[$blockname]))
154 $this->data[$blockname] = array();
155
156 if (! is_array($data) )
157 {
158 $this->data[$blockname] = $data; // happens on root display fields
159 }
160 else
161 {
162 foreach($data as $key => $field)
163 {
164 $this->data[$blockname][$key] = $field;
165 }
166 }
167 //sync
168 foreach($this->blocks as $name => $block)
169 {
170 // run every blocks setter
171 $block->set($this->data);
172 }
173 }
174
175 public function setHook($hook)
176 {
177 $this->doingHook = $hook;
178 $this->setEnv();
179 }
180
181 /** Change the internal counter. This is useful for ajax request, or other situations where there is already collection on screen */
182 public static function setCount($count)
183 {
184 static::$count = $count;
185 }
186
187 // sets the style object to a collection. This is important for styling CSS
188 public function setStyle($style)
189 {
190 if (! is_object($style))
191 return false;
192
193 $this->styleObj = $style;
194 $style->setActive($this);
195 }
196
197 public function getStyle()
198 {
199 return $this->styleObj;
200
201 }
202
203 public function getHook()
204 {
205 if (is_null($this->doingHook))
206 return false;
207 else
208 return $this->doingHook;
209 }
210
211 public function setEnv() // load orientations and specifics about the current collections. After data has loaded and all that.
212 {
213 $w = MBSocial()->whistle();
214
215 $data = $this->data;
216
217 $hook = $this->doingHook;
218
219 $display = isset($this->data[$hook]) ? $this->data[$hook] : 'hidden';
220 if ($this->doingHook == 'shortcode')
221 $display = 'shortcode'; // exception
222
223 $this->display_mode = $display;
224
225
226 if (! is_admin() && is_singular() )
227 {
228 global $post;
229 $this->post_id = $post->ID;
230 }
231 else
232 $this->post_id = 0;
233
234
235 if ($display == 'static')
236 {
237 $this->is_static = true;
238 }
239 elseif ($display == 'after' || $display == 'before' || $display == 'after-before' || $display == 'shortcode')
240 $this->is_post = true;
241
242 // check if on some mobile
243 $mobileDetect = new Mobile_Detect;
244 $this->is_mobile = $mobileDetect->isMobile();
245 $this->is_tablet = $mobileDetect->isTablet();
246
247 $options = isset($data['display'][$hook . '_options']) ? $data['display'][$hook . '_options'] : array();
248
249 $orientation = isset($options['orientation']) ? $options['orientation'] : 'auto';
250 $static = isset($options['static']) ? $options['static'] : 'auto';
251
252 if ($orientation == 'auto' && $display == 'static')
253 {
254 switch($static) // auto align on basis of placement on screen
255 {
256 case "left": // vertical items
257 case "right":
258 case "auto":
259 $orientation = "vertical";
260 break;
261 case "top": // horizontal
262 case "bottom":
263 default:
264 $orientation = "horizontal";
265 break;
266 }
267 }
268 elseif ($orientation == 'auto')
269 {
270 $orientation = 'horizontal';
271 }
272
273 $this->orientation = $orientation;
274
275 // Check if any hidden variables are given.
276 $is_active = isset($this->data['general']['active']) ? $this->data['general']['active'] : true;
277
278 if ($is_active === 0)
279 {
280 $this->is_showable = false;
281 }
282
283 if ($this->post_id > 0)
284 {
285 $meta = $this->get_metadata($this->post_id);
286 $is_old_active = (isset($meta['general']['active'])) ? $meta['general']['active'] : true;
287
288 $is_hidden = isset($meta['general']['hide']) ? $meta['general']['hide'] : 0;
289 if ($is_hidden == 1)
290 {
291 $this->is_showable = false;
292 }
293 elseif (isset($meta['general']['active']) && $is_old_active === 0) // backward for 0.9.5 . Can go at some point
294 $this->is_showable = false;
295 }
296
297 // new method of getting data around
298 $w->tell('display/env/hook', $hook);
299 $w->tell('display/env/post_id', $this->post_id);
300 $w->tell('display/env/is_static', $this->is_static );
301 $w->tell('display/env/is_post',$this->is_post);
302 $w->tell('display/env/is_mobile', $this->is_mobile);
303 $w->tell('display/env/is_tablet', $this->is_tablet);
304 $w->tell('display/env/is_active', $this->is_showable);
305
306 }
307
308 /** Interface for handling AJAX requests to communicate with the seperate blocks.
309 * @param $result The initial (default) result to JSON back
310 * @param $block_name The name of the block in question
311 * @param $action The name of the block function to call
312 * @param $data Data specified by JS to use for this function
313 * @return $result - Standardized result block including error, body
314 */
315 public function doBlockAJAX($result, $block_name, $action, $data)
316 {
317 // core class is being called.
318 if ($block_name == 'collection')
319 {
320 $result = $this->$action($result, $data);
321 return $result;
322 }
323
324 if (isset($this->blocks[$block_name]))
325 {
326 $block= $this->blocks[$block_name];
327 $result = $block->$action($result, $data);
328 return $result;
329
330 }
331
332 $result["error"] = true;
333 $result["title"] = __("Error : Block was not there","maxbuttons");
334 return $result;
335 }
336
337 /** Save the collection post data to the database. This will invoke the save functions of the blocks itself to gather, verify and manipulate data */
338 public function save($post)
339 {
340 $data = array();
341
342 // run this by each block and collect data
343 foreach($this->blocks as $block_name => $block)
344 {
345
346 $data = $block->save_fields($data, $post);
347 }
348
349 $this->data = $data;
350 return $this->saveData();
351
352 }
353
354 /* The actual save function. Save data to the database */
355 public function saveData()
356 {
357 // Collection id needed to save meta data and others.
358 if ($this->collection_id == 0) // assume new
359 {
360 $collection_id = $this->getNewCollectionID();
361
362 $this->collection_id = $collection_id;
363 }
364
365 // clean what was not set
366 $this->clean_meta($this->data);
367
368 // write data as a per block per key value into the database
369 foreach($this->data as $blockname => $blockdata)
370 {
371 // seems dangerous
372 $meta_id = $this->update_meta($this->collection_id, $blockname, $blockdata);
373 }
374
375 // insert collection type
376 $this->update_meta($this->collection_id, 'collection_type', 'social_share') ;
377
378 return $this->collection_id;
379 }
380
381 // remove post meta not in data post.
382 public function clean_meta($data)
383 {
384 $data_blocks = array_keys($data);
385
386 $meta = $this->get_meta();
387
388 foreach($meta as $meta_key => $values)
389 {
390 if (! in_array($meta_key, $data_blocks))
391 {
392 $this->delete_meta($this->collection_id, $meta_key);
393 }
394 }
395
396 }
397
398 public function update_meta($collection_id, $collection_key, $collection_value)
399 {
400 global $wpdb;
401 $table = maxUtils::get_collection_table_name();
402
403 if ($collection_value == '') return; // no data no database entry
404 if (is_array($collection_value) && count($collection_value) == 0) return; // same for empty arrays
405
406 if (is_array($collection_value))
407 $collection_value = json_encode($collection_value);
408
409 if ($collection_id == 0) // assume new
410 {
411 $collection_id = $this->getNewCollectionID();
412
413 $this->collection_id = $collection_id;
414 }
415
416 $sql = "SELECT meta_id from $table where collection_id = %d and collection_key = %s ";
417 $sql = $wpdb->prepare($sql, $collection_id, $collection_key);
418
419 $results = $wpdb->get_results($sql, ARRAY_A);
420
421 if (count($results) == 1)
422 {
423 $meta_id = $results[0]["meta_id"];
424 $data = array("collection_value" => $collection_value); // what's being updated
425 $where = array("meta_id" => $meta_id);
426
427 $wpdb->update($table, $data, $where);
428 return $meta_id;
429 }
430 if (count($results) == 0)
431 {
432 $data = array("collection_value" => $collection_value,
433 "collection_key" => $collection_key,
434 "collection_id" => $collection_id,
435 );
436
437 $meta_id = $wpdb->insert($table, $data);
438
439 return $meta_id;
440 }
441 else
442 {
443 MB()->add_notice("error", __("Update Collection meta has multiple rows, this should not be possible.","maxbuttons"));
444
445 }
446 return false;
447 }
448
449
450 /** Determine the next ID for collection */
451 protected function getNewCollectionID()
452 {
453 global $wpdb;
454 $table = maxUtils::get_collection_table_name();
455
456 $sql = "SELECT max(collection_id) as max from $table";
457
458 $max = intval($wpdb->get_var($sql));
459
460 $max = $max + 1;
461 return $max;
462 }
463
464 protected function delete_meta($collection_id, $collection_key)
465 {
466 if (intval($collection_id) > 0 && $collection_key != "")
467 {
468 global $wpdb;
469 // delete_post_meta($collection_id, $collection_key);
470 $table = maxUtils::get_collection_table_name();
471 $where = array("collection_id" => $collection_id,
472 "collection_key" => $collection_key
473 );
474 $where_format = array("%d", "%s");
475 $wpdb->delete($table, $where, $where_format);
476
477 }
478 }
479
480
481 /** Delete the collection. This is done via AJAX request */
482 /*public function delete($result, $data)
483 {
484 global $wpdb;
485 if(! $this->collection_id > 0)
486 return false;
487
488 $picker = $this->getBlock("picker");
489 $picker_data = $picker->get();
490 $buttons = $picker_data["selection"];
491 $button = MB()->getClass("button");
492
493 $buttons_removed = 0;
494
495 foreach($buttons as $button_id)
496 {
497 $deleted = $this->maybe_delete_button($button_id);
498 if ($deleted)
499 $buttons_removed++;
500
501 }
502
503 $table = maxUtils::get_collection_table_name();
504 $where = array("collection_id" => $this->collection_id);
505 $where_format = array("%d");
506 $wpdb->delete($table, $where, $where_format);
507
508 $result["data"]["body"] = __("The collection is removed","maxbuttons");
509 $result["data"]["title"] = __("Removed","maxbuttons");
510 $result["data"]["buttons_removed"] = $buttons_removed;
511 $result["data"]["collection_id"] = $this->collection_id;
512 return $result;
513
514
515 } */
516
517 /** On deletion of a collection check for each button if this is an auto-generated button just made for this collection * and if
518 * no changes where made to this button. If both conditions are true, remove the button */
519 /*function maybe_delete_button($button_id)
520 {
521 $button = MB()->getClass("button");
522
523 $button->set($button_id);
524 $button_data = $button->get();
525
526 $collection_id= $this->collection_id;
527
528 // remove unedited buttons created for this collection - use with care.
529 if (isset($button_data["meta"]["user_edited"]))
530 {
531 $created_source = (isset($button_data["meta"]["created_source"])) ? $button_data["meta"]["created_source"] : '';
532 if ($button_data["meta"]["user_edited"] === false && $created_source == 'collection')
533 {
534 $in_collections = $button_data["meta"]["in_collections"];
535
536 $key = array_search($collection_id, $in_collections);
537
538 if ($key !== false)
539 {
540 unset($button_data["meta"]["in_collections"][$key]);
541
542 if (count($button_data["meta"]["in_collections"]) == 0)
543 { $button->delete($button_id);
544 return true;
545 }
546 else
547 {
548 if ($button_id > 0) // safety.
549 $button->update($button_data);
550 }
551 }
552 }
553
554
555 }
556 return false;
557 } */
558
559 function get_meta ($collection_key = '')
560 {
561 global $wpdb;
562 $table = maxUtils::get_collection_table_name();
563
564 $prepare = array($this->collection_id);
565
566 $sql = "SELECT * from $table where collection_id = %d ";
567 if ($collection_key != '')
568 {
569 $sql .= " and collection_key = %s ";
570 array_push($prepare, $collection_key);
571
572 }
573
574 $sql = $wpdb->prepare($sql, $prepare);
575
576 $results = $wpdb->get_results($sql, ARRAY_A);
577
578 $result_array = array(); // format array by field name = values to feed blocks and others.
579 if (! is_null($results))
580 {
581
582 $nr = array();
583 foreach($results as $row)
584 {
585 $key = $row["collection_key"];
586 /* A field can be either plain text or JSON */
587 if(json_decode($row["collection_value"]))
588 $value = json_decode($row["collection_value"], true);
589 else
590 $value = $row["collection_value"];
591
592 $result_array[$key] = $value;
593
594 //$row["collection_value"] = unserialize($row["collection_value"]);
595 }
596
597 return $result_array;
598 }
599 else
600 {
601 return false;
602 }
603 }
604
605 function display($args = array())
606 {
607 if (! $this->is_showable)
608 return;
609
610
611 /*if (method_exists(MB(), 'load_library'))
612 {
613 MB()->load_library('fontawesome'); // always load lib since change is about 100% this includes FA.
614 } */
615
616 maxUtils::startTime('collection-display-' . self::$count);
617
618 $w = MBSocial()->whistle();
619
620 wp_enqueue_style('mbsocial-buttons'); // load the general button style
621 wp_enqueue_script('mbsocial_front');
622
623
624 $defaults = array(
625 "preview" => false,
626 "echo" => true,
627 "style_tag" => false,
628 "compile" => false,
629 "js_tag" => true,
630 "load_type" => "footer",
631 );
632
633 $args = wp_parse_args($args, $defaults);
634
635 $w->tell('display/env/is_preview', $args['preview']);
636
637
638 //$cache = MaxCollections::checkCachedCollection($this->collection_id);
639 $cache = false;
640
641 if (! $cache)
642 {
643 //$cssParser = $this->getCSSParser();
644 $domObj = $this->parse($args);
645
646 //$css = $this->parseCSS($args);
647
648 $js = $this->parseJS($args);
649
650 $output = $domObj->save();
651
652 unset($domObj);
653
654
655 // CSS & JS output control
656 $output .= $this->displayCSS($this->css, $args);
657 $output .= $this->displayJS($js, $args);
658 }
659 else
660 $output = $cache;
661
662 //collections::addCachedCollection($this->collection_id, $output);
663
664 maxUtils::endTime('collection-display-' . self::$count);
665
666 if ($args["echo"])
667 {
668 echo $output;
669 }
670 else
671 {
672 return $output;
673 }
674
675 }
676
677 public function displayCSS($css, $args = array() ) // $echo = true, $style_tag = true)
678 {
679
680 $default = array(
681 "echo" => true,
682 "style_tag" => true,
683 "load_type" => "footer",
684 );
685 $args = wp_parse_args($args, $default);
686 if ($args['load_type'] == 'inline')
687 $args['style_tag'] =true;
688
689 $output = '';
690
691 if ($args["style_tag"])
692 $output .= "<style type='text/css'>";
693
694 $output .= $css;
695
696 if ($args["style_tag"])
697 $output .= "</style>";
698
699
700 if ($args["load_type"] == 'footer')
701 {
702 $load_id = 'collection-' . $this->collection_id; // must be unique for unique items, otherwise css won't be output
703
704 if (self::$count > 1)
705 {
706 $load_id .= "-" . self::$count;
707 }
708
709 do_action('mb-footer',$load_id, $output);
710 }
711 elseif ($args["load_type"] == 'inline')
712 {
713 if ($args["echo"]) echo $output;
714 else return $output;
715
716 }
717
718 }
719
720 public function displayJS($js, $args = array() ) // $echo = true, $style_tag = true)
721 {
722 $default = array(
723 "echo" => true,
724 "js_tag" => true,
725 "load_type" => "footer",
726 "preview" => false,
727 );
728
729
730 $args = wp_parse_args($args, $default);
731
732 if ($args["preview"])
733 return; // no js on previews.
734
735 $output = '';
736
737 if (count($js) == 0)
738 return; // no output, holiday
739
740 if ($args["js_tag"])
741 {
742 $output .= "<script type='text/javascript'> ";
743 // $output .= " if (typeof MBcollection" . $this->collection_id . " == 'undefined') { ";
744 // $output .= " function MBcollection" . $this->collection_id . "() { ";
745
746
747 }
748
749 foreach($js as $index => $code)
750 {
751 $output .= $code;
752 }
753
754 if ($args["js_tag"])
755 {
756 $output .= " // }
757 // }
758 // window.onload = MBcollection" . $this->collection_id . "();
759 </script> ";
760 }
761
762
763 if ($args["load_type"] == 'footer')
764 {
765
766 do_action('mb-footer','collection-' . $this->collection_id, $output, "js");
767 }
768 elseif ($args["load_type"] == 'inline')
769 {
770 if ($args["echo"]) echo $output;
771 else return $output;
772
773 }
774 }
775
776 /* Parses the collection, via the blocks */
777 function parse($args)
778 {
779 $admin = mbSocial()->admin();
780 $w = MBSocial()->whistle();
781 $cssParser = $this->getCSSParser();
782 maxUtils::startTime('collection-parse-'. self::$count);
783
784 //$this->setEnv(); // sets the relevant data for the block (orientation etc)
785 $this->buttons = array(); // reset the buttons - needed for preview
786
787 $is_preview = isset($args["preview"]) ? $args["preview"] : false;
788
789 $collectionObj = new simple_html_dom();
790 $collection_id = $this->collection_id;
791
792 $styleObj = $this->styleObj;
793 $style_class = ''; //$styleObj->class;
794 $style_class = $this->orientation;
795
796 // create container
797 if (self::$count > 1)
798 {
799 $style_class .= ' doc-' . self::$count;
800 }
801 $node = "<div class='maxsocial maxsocial-" . $collection_id . " $style_class ' data-collection='" . $collection_id . "'>
802 </div>";
803 $node = apply_filters("maxbuttons/social/basic-container",$node);
804
805 $collectionObj->load($node);
806
807 $active = ( isset($this->data['network']['network_active']) && is_array($this->data['network']['network_active']) ) ? $this->data['network']['network_active'] : array();
808 if (count($active) == 0 && $args['preview'] == true)
809 {
810 $networks = $admin->get_default_networks();
811 $use_networks = $networks['unselected'];
812 }
813 elseif (count($active) == 0)
814 return $collectionObj; // no networks no collection
815 else
816 {
817 $networks = $admin->get_networks($active);
818 $use_networks = $networks['selected'];
819 }
820
821 $index = 0; // used as unique button_id
822
823 maxUtils::startTime('collection-parse-network-' . self::$count);
824 foreach($use_networks as $network)
825 {
826 if (! is_object($network))
827 {
828 continue;
829 }
830 $w->tell('display/parse/network', $network);
831
832 $button_args = array('link' => $network->get_url(),
833 'preview' => $is_preview,
834 'index' => $index,
835 'name' => $network->get('network'),
836 'data' => $this->data,
837 'collection_count' => self::$count,
838 );
839
840 $button_args = apply_filters('mbsocial/parsebutton/args', $button_args);
841 $button = $network->createButton($button_args);
842
843 // empty response == skip button
844 if (! $button || ! is_object($button))
845 continue;
846
847
848 foreach($this->blocks as $block)
849 {
850 /** Here some reset to block and to style, to denote new button creation. */
851 $block->setPreview($is_preview);
852 $button = $block->parse($button, $button_args);
853 }
854
855 if ($button)
856 {
857
858 // save DOM structure to parser
859 $cssParser->loadDom($button);
860 $css = '';
861
862 $css = $this->parseCSS( array('preview' => $is_preview) );
863
864 $this->buttons[] = array('item_class' => $button_args['name'],
865 'obj' => $button,
866 'css' => $css,
867 );
868
869 }
870
871 $index++;
872
873 } // network loop.
874 maxUtils::endTime('collection-parse-network-' . self::$count);
875
876 // general parsing
877 $button_output = '';
878 $css = '';
879
880 foreach($this->buttons as $button_item)
881 {
882 $buttonDom = $button_item['obj'];
883 $button_output .= $buttonDom->save() ;
884 $css .= $button_item['css'];
885 }
886
887 $count_block = $this->blocks['countBlock'];
888 $count_block->createTotal($collectionObj);
889
890 $cssParser->loadDom($collectionObj);
891 $css .= $this->parseCSS( array('preview' => $is_preview, 'skip_blocks' => true) );
892
893 $this->css = $css;
894
895 $collectionObj->find('.maxsocial', 0)->innertext .= $button_output;
896 $collectionObj->load($collectionObj->save());
897
898 maxUtils::endTime('collection-parse-'. self::$count);
899 return $collectionObj;
900 }
901
902
903 protected function parseCSS($args)
904 {
905 maxUtils::startTime('collection-parseCSS-'. self::$count);
906 $defaults = array(
907 'preview' => false,
908 'skip_blocks' => false
909 );
910 $args = wp_parse_args($args, $defaults);
911
912
913 $css = array();
914 if (! is_null($this->styleObj))
915 {
916 $prep_args = array(
917 'orientation' => $this->orientation,
918 'is_static' => $this->is_static,
919 'is_mobile' => $this->is_mobile,
920 'is_tablet' => $this->is_tablet,
921 'is_post' => $this->is_post);
922
923 $this->styleObj->prepareCSS($prep_args);
924 $css = $this->styleObj->getCSS();
925 }
926
927 foreach($this->blocks as $block)
928 {
929 // This needs changes to accomodate to parse the defined SCSS stylesheet instead of using CSSParser which will not work here.
930 // It will not work because CSSparse expects a very precise class definition and not a general broad definition of the items.
931 $css = $block->parseCSS($css, $args);
932
933 }
934
935 // before the parse let have style have one more go
936 $css = $this->styleObj->preParse($css);
937 $css = apply_filters('mbsocial/parsecss/', $css); // anybody else
938
939 $css = $this->getCSSParser()->parse($css);
940 maxUtils::endTime('collection-parseCSS-'. self::$count);
941 return $css;
942 }
943
944 protected function parseJS($args)
945 {
946 $js = array();
947
948 $defaults = array("preview" => false,
949 );
950
951 $args = wp_parse_args($args, $defaults);
952
953 if ($args["preview"])
954 return false; // no js on previews
955
956 foreach($this->blocks as $block)
957 {
958 $js = $block->parseJS($js, $args);
959
960 }
961
962 return $js;
963 }
964
965
966
967
968 /** Metadata functions **/
969
970 public function get_metadata($post_id)
971 {
972 if ( ! is_array($this->meta_data) || count ($this->meta_data) == 0)
973 {
974 $data = get_post_meta($post_id, 'mbsocial_data', true);
975 $this->meta_data = $data;
976 }
977
978 return $this->meta_data;
979 }
980
981 public function do_meta_boxes($post_type, $post)
982 {
983 $content_blocks = array();
984
985 foreach($this->blocks as $block)
986 {
987 $content_blocks = $block->do_meta_boxes($content_blocks, $post);
988 }
989
990 return $content_blocks;
991 }
992
993 /** @param $post_id Saving post_id
994 * @param $post Post Array of submitted values
995 **/
996 public function save_meta_boxes($post_id, $post)
997 {
998 $post_meta = array();
999
1000 foreach($this->blocks as $block)
1001 {
1002 $post_meta = $block->save_meta_boxes($post_meta, $post_id, $post);
1003
1004 }
1005
1006 if (count($post_meta) > 0)
1007 update_post_meta($post_id, 'mbsocial_data', $post_meta);
1008 }
1009
1010 function showBlocks()
1011 {
1012 foreach($this->blocks as $block)
1013 {
1014 echo $block->admin();
1015 }
1016
1017 $active = isset($this->data['network']['network_active']) ? $this->data['network']['network_active'] : array();
1018
1019 if ( is_array($active) && count($active) > 0)
1020 {
1021 foreach($active as $network_name)
1022 {
1023 $network = MbSocial()->networks()->get($network_name);
1024 if ( is_object($network))
1025 echo $network->admin($this->data);
1026 }
1027 }
1028 }
1029 } //class
1030