PluginProbe ʕ •ᴥ•ʔ
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel / trunk
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel vtrunk
trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / admin / class-demo-content.php
foogallery / includes / admin Last commit date
class-admin-notice-custom-css.php 7 months ago class-admin-notices.php 7 months ago class-admin.php 7 months ago class-attachment-fields.php 7 months ago class-columns.php 7 months ago class-demo-content.php 7 months ago class-extensions.php 7 months ago class-gallery-attachment-modal.php 7 months ago class-gallery-datasources.php 7 months ago class-gallery-editor.php 7 months ago class-gallery-metabox-fields.php 7 months ago class-gallery-metabox-items.php 7 months ago class-gallery-metabox-settings-helper.php 7 months ago class-gallery-metabox-settings.php 7 months ago class-gallery-metabox-template.php 7 months ago class-gallery-metaboxes.php 7 months ago class-menu.php 7 months ago class-pro-promotion.php 7 months ago class-settings.php 7 months ago class-silent-installer-skin.php 7 months ago class-trial-mode.php 7 months ago demo-content-galleries.php 7 months ago demo-content-images.php 7 months ago index.php 11 years ago pro-features.php 7 months ago view-features.php 7 months ago view-help-demos.php 7 months ago view-help-getting-started.php 7 months ago view-help-pro.php 7 months ago view-help.php 7 months ago view-system-info.php 7 months ago
class-demo-content.php
153 lines
1 <?php
2 /*
3 * FooGallery Admin Demo Content class
4 */
5
6 if ( ! class_exists( 'FooGallery_Admin_Demo_Content' ) ) {
7
8 class FooGallery_Admin_Demo_Content {
9
10 /**
11 * Import attachments and galleries
12 *
13 * @return int[]
14 */
15 function import_demo_content() {
16 //import all the images first, so that we can get attachment ID's
17 $image_data = include( FOOGALLERY_PATH . 'includes/admin/demo-content-images.php' );
18
19 $images_imported = 0;
20 $attachment_mappings = array();
21
22 foreach ( $image_data as $attachment_data ) {
23 $result = $this->import_attachment( $attachment_data );
24 if ( $result !== false ) {
25 if ( $result['imported'] ) {
26 $images_imported++;
27 }
28 $attachment_mappings[ $result['key'] ] = intval( $result['attachment_id'] );
29 }
30 }
31
32 $gallery_data = include( FOOGALLERY_PATH . 'includes/admin/demo-content-galleries.php' );
33
34 $galleries_imported = 0;
35
36 foreach ( $gallery_data as $post_data ) {
37 //create the post
38 $result = $this->import_gallery( $post_data, $attachment_mappings );
39 if ( $result !== false ) {
40 if ( $result['imported'] ) {
41 $galleries_imported++;
42 }
43 }
44 }
45
46 return array(
47 'attachments' => $images_imported,
48 'galleries' => $galleries_imported
49 );
50 }
51
52 function import_gallery( $gallery_data, $attachment_mappings ) {
53 $imported_galleries = get_option( FOOGALLERY_OPTION_DEMO_CONTENT_GALLERIES, array() );
54
55 $key = $gallery_data['key'];
56
57 //check to see if the gallery has already been imported
58 if ( array_key_exists( $key, $imported_galleries ) ) {
59 $gallery_id = $imported_galleries[ $key ];
60 //check that the gallery actually exists
61 if ( get_post_status ( $gallery_id ) ) {
62 return array(
63 'id' => $gallery_id,
64 'imported' => false
65 );
66 }
67 }
68
69 $items = $gallery_data['items'];
70 unset( $gallery_data['items'] );
71 unset( $gallery_data['key'] );
72
73 $gallery_id = wp_insert_post( $gallery_data, true );
74 $imported = true;
75
76 if ( !is_wp_error( $gallery_id ) ) {
77
78 if ( $imported ) {
79 //save the gallery to options so we can delete easily it later
80 $imported_galleries = get_option( FOOGALLERY_OPTION_DEMO_CONTENT_GALLERIES, array() );
81 $imported_galleries[ $key ] = $gallery_id;
82 update_option( FOOGALLERY_OPTION_DEMO_CONTENT_GALLERIES, $imported_galleries );
83 }
84
85 $attachments = array();
86
87 //get the attachment ID's and set the attachment metadata
88 foreach ( $items as $item ) {
89 if ( array_key_exists( $item, $attachment_mappings ) ) {
90 $attachments[] = $attachment_mappings[ $item ];
91 }
92 }
93
94 update_post_meta( $gallery_id, FOOGALLERY_META_ATTACHMENTS, $attachments );
95
96 return array(
97 'id' => $gallery_id,
98 'imported' => $imported
99 );
100 }
101
102 return false;
103 }
104
105 /**
106 * Import an attachment into the media library
107 *
108 * @param $attachment_data
109 *
110 * @return array|bool
111 */
112 function import_attachment( $attachment_data ) {
113
114 $imported_attachments = get_option( FOOGALLERY_OPTION_DEMO_CONTENT_ATTACHMENTS, array() );
115
116 //check to see if the image has already been imported
117 if ( array_key_exists( $attachment_data['key'], $imported_attachments ) ) {
118 $attachment_id = $imported_attachments[ $attachment_data['key'] ];
119 //check that the attachment actually exists
120 if ( get_post_status ( $attachment_id ) ) {
121 return array(
122 'key' => $attachment_data['key'],
123 'attachment_id' => $attachment_id,
124 'imported' => false
125 );
126 }
127 }
128
129 $attachment_id = foogallery_import_attachment( $attachment_data );
130
131 if ( ! is_wp_error( $attachment_id ) && intval( $attachment_id ) > 0 ) {
132
133 $imported_attachments[ $attachment_data['key'] ] = $attachment_id;
134
135 update_option( FOOGALLERY_OPTION_DEMO_CONTENT_ATTACHMENTS, $imported_attachments );
136
137 return array(
138 'key' => $attachment_data['key'],
139 'attachment_id' => $attachment_id,
140 'imported' => true,
141 );
142 }
143
144 return array(
145 'key' => $attachment_data['key'],
146 'attachment_id' => false,
147 'imported' => false,
148 );
149 }
150 }
151 }
152
153