1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10: $plugin_is_filter = 600 | THEME_PLUGIN | ADMIN_PLUGIN;
11: $plugin_description = gettext('Create news articles when a gallery item is published.');
12: $plugin_author = "Stephen Billard (sbillard)";
13: $plugin_disable = extensionEnabled('zenpage') ? '' : gettext('Gallery Articles requires Zenpage to be enabled.');
14:
15: $option_interface = 'galleryArticles';
16:
17: zp_register_filter('show_change', 'galleryArticles::published');
18: if (getOption('galleryArticles_albums'))
19: zp_register_filter('new_album', 'galleryArticles::published');
20: if (getOption('galleryArticles_images'))
21: zp_register_filter('new_image', 'galleryArticles::published');
22: zp_register_filter('admin_head', 'galleryArticles::scan');
23: zp_register_filter('load_theme_script', 'galleryArticles::scan');
24:
25: 26: 27: 28: 29: 30:
31: class galleryArticles {
32:
33: function __construct() {
34: if (OFFSET_PATH == 2) {
35: setOptionDefault('galleryArticles_images', NULL);
36: setOptionDefault('galleryArticles_albums', NULL);
37: setOptionDefault('galleryArticles_category', NULL);
38: setOptionDefault('galleryArticles_albumCategory', 0);
39: $text = gettext('New album: %1$s');
40: setOptionDefault('galleryArticles_album_text', getAllTranslations($text));
41: $text = gettext('New image: [%2$s]%1$s');
42: setOptionDefault('galleryArticles_image_text', getAllTranslations($text));
43: setOptionDefault('galleryArticles_size', 80);
44: setOptionDefault('galleryArticles_protected', 0);
45: if (class_exists('cacheManager')) {
46: cacheManager::deleteThemeCacheSizes('galleryArticles');
47: cacheManager::addThemeCacheSize('galleryArticles', getOption('galleryArticles_size'), NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, NULL, NULL);
48: }
49: }
50: }
51:
52: 53: 54: 55:
56: function getOptionsSupported() {
57: global $_zp_zenpage;
58: if ($_zp_zenpage) {
59: $categories = array();
60: $list = $_zp_zenpage->getAllCategories();
61: foreach ($list as $cat) {
62: $categories[get_language_string($cat['title'])] = $cat['titlelink'];
63: }
64:
65: $list = array('<em>' . gettext('Albums') . '</em>' => 'galleryArticles_albums', '<em>' . gettext('Images') . '</em>' => 'galleryArticles_images');
66:
67: $options = array(gettext('Publish for') => array('key' => 'galleryArticles_items', 'type' => OPTION_TYPE_CHECKBOX_ARRAY,
68: 'order' => 1,
69: 'checkboxes' => $list,
70: 'desc' => gettext('If a <em>type</em> is checked, a news article will be made when an object of that <em>type</em> is published. Note: These articles are static and will not be updated automatically if the original changes later!')),
71: gettext('Image title') => array('key' => 'galleryArticles_image_text', 'type' => OPTION_TYPE_TEXTBOX,
72: 'order' => 3,
73: 'multilingual' => true,
74: 'desc' => gettext('This text will be used as the <em>title</em> of the article. The album title will be substituted for <code>%2$s</code> and the image title for <code>%1$s</code>.')),
75: gettext('Album title') => array('key' => 'galleryArticles_album_text', 'type' => OPTION_TYPE_TEXTBOX,
76: 'order' => 2,
77: 'multilingual' => true,
78: 'desc' => gettext('This text will be used as the <em>title</em> of the article. The album title will be substituted for <code>%1$s</code>.')),
79: gettext('Size') => array('key' => 'galleryArticles_size', 'type' => OPTION_TYPE_TEXTBOX,
80: 'order' => 5,
81: 'desc' => gettext('Set the size the image will be displayed.')),
82: gettext('Publish protected') => array('key' => 'galleryArticles_protected', 'type' => OPTION_TYPE_CHECKBOX,
83: 'order' => 4,
84: 'desc' => gettext('Unless this is checked, objects which are "protected" will not have news articles generated.')),
85: gettext('Category') => array('key' => 'galleryArticles_category', 'type' => OPTION_TYPE_SELECTOR,
86: 'order' => 6,
87: 'selections' => $categories,
88: 'desc' => gettext('Select a category for the generated articles')),
89: gettext('Use album folder') => array('key' => 'galleryArticles_albumCategory', 'type' => OPTION_TYPE_CHECKBOX,
90: 'order' => 7,
91: 'desc' => gettext('If this option is checked and a category matching the album folder exists, that will be used as the article category.'))
92: );
93: if (getOption('zenpage_combinews')) {
94: $options[gettext('Import Combi-news')] = array('key' => 'galleryArticles_import', 'type' => OPTION_TYPE_CHECKBOX,
95: 'order' => 99,
96: 'desc' => gettext('If this option is checked, articles will be generated based on your old <em>Combi-news</em> settings.'));
97: }
98: } else {
99: $options = array(gettext('Disabled') => array('key' => 'galleryArticles_note', 'type' => OPTION_TYPE_NOTE,
100: 'desc' => '<p class="notebox">' . gettext('Gallery Articles requires Zenpage to be enabled.') . '</p>'));
101: }
102: return $options;
103: }
104:
105: 106: 107: 108: 109: 110:
111: function handleOption($option, $currentValue) {
112:
113: }
114:
115: function handleOptionSave($themename, $themealbum) {
116: if (getOption('galleryArticles_import')) {
117: require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/galleryArticles/combiNews.php');
118: purgeOption('galleryArticles_import');
119: }
120: return false;
121: }
122:
123: 124: 125: 126: 127:
128: static function published($obj) {
129: self::publishArticlesWithCheck($obj);
130: return $obj;
131: }
132:
133: 134: 135: 136: 137:
138: private static function publishArticlesWithCheck($obj) {
139: $type = $obj->table;
140: if (getOption('galleryArticles_' . $type)) {
141: if ($obj->getShow()) {
142: if (getOption('galleryArticles_protected') || !$obj->isProtected()) {
143: switch ($type = $obj->table) {
144:
145: case 'albums':
146: $dt = $obj->getPublishDate();
147: if ($dt > date('Y-m-d H:i:s')) {
148: $result = query_single_row('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `type`="galleryArticles" AND `aux`="pending_albums" AND `data`=' . db_quote($obj->name));
149: if (!$result) {
150: query('INSERT INTO ' . prefix('plugin_storage') . ' (`type`,`aux`,`data`) VALUES ("galleryArticles","pending_albums",' . db_quote($obj->name) . ')');
151: }
152: } else {
153: self::publishArticle($obj);
154: }
155: break;
156: case 'images':
157: $dt = $obj->getPublishDate();
158: if ($dt > date('Y-m-d H:i:s')) {
159: $result = query_single_row('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `type`="galleryArticles" AND `aux`="pending_images" AND `data`=' . db_quote($obj->imagefolder . '/' . $obj->filename));
160: if (!$result) {
161: query('INSERT INTO ' . prefix('plugin_storage') . ' (`type`,`aux`,`data`) VALUES ("galleryArticles","pending_images",' . db_quote($obj->imagefolder . '/' . $obj->filename) . ')');
162: }
163: } else {
164: self::publishArticle($obj);
165: }
166: break;
167: }
168: }
169: }
170: }
171: }
172:
173: 174: 175: 176: 177:
178: private static function publishArticle($obj, $override = NULL) {
179: global $_zp_zenpage;
180: $galleryitem_text = array();
181: switch ($type = $obj->table) {
182: case 'albums':
183: if (getOption('multi_lingual')) {
184: $option_text = unserialize(getOption('galleryArticles_album_text'));
185: foreach ($option_text as $key => $val) {
186: $galleryitem_text[$key] = sprintf($option_text[$key], $obj->getTitle($key));
187: }
188: $text = serialize($galleryitem_text);
189: } else {
190: $text = sprintf(get_language_string(getOption('galleryArticles_album_text')), $obj->getTitle());
191: }
192: $title = $folder = $obj->name;
193: $img = $obj->getAlbumThumbImage();
194: $class = 'galleryarticles-newalbum';
195: break;
196: case 'images':
197: if (getOption('multi_lingual')) {
198: $option_text = unserialize(getOption('galleryArticles_image_text'));
199: foreach ($option_text as $key => $val) {
200: $galleryitem_text[$key] = sprintf($option_text[$key], $obj->getTitle($key), $obj->album->getTitle($key));
201: }
202: $text = serialize($galleryitem_text);
203: } else {
204: $text = sprintf(get_language_string(getOption('galleryArticles_image_text')), $obj->getTitle(), $obj->album->getTitle());
205: }
206: $folder = $obj->imagefolder;
207: $title = $folder . '-' . $obj->filename;
208: $img = $obj;
209: $class = 'galleryarticles-newimage';
210: break;
211: }
212: $article = new ZenpageNews(seoFriendly('galleryArticles-' . $title));
213: $article->setTitle($text);
214: $imglink = $img->getCustomImage(getOption('galleryArticles_size'), NULL, NULL, NULL, NULL, NULL, NULL, -1);
215: if (getOption('multi_lingual')) {
216: $desc = '';
217: foreach ($option_text as $key => $val) {
218: $desc[$key] = '<p><a class="' . $class . '" href="' . $obj->getLink() . '"><img src="' . $imglink . '"></a></p><p>' . $obj->getDesc($key) . '</p>';
219: }
220: $desc = serialize($desc);
221: } else {
222: $desc = '<p><a class="' . $class . '" href="' . $obj->getLink() . '"><img src="' . $imglink . '"></a></p><p>' . $obj->getDesc() . '</p>';
223: }
224: $article->setContent($desc);
225: $article->setShow(true);
226: $date = $obj->getPublishDate();
227: if (!$date) {
228: $date = date('Y-m-d H:i:s');
229: }
230: $article->setDateTime($date);
231: $article->setAuthor('galleryArticles');
232: $article->save();
233: if ($override) {
234: $cat = $override;
235: } else {
236: $cat = getOption('galleryArticles_category');
237: if (getOption('galleryArticles_albumCategory')) {
238: $catlist = $_zp_zenpage->getAllCategories();
239: foreach ($catlist as $category) {
240: if ($category['titlelink'] == $folder) {
241: $cat = $category['titlelink'];
242: break;
243: }
244: }
245: }
246: }
247: $article->setCategories(array($cat));
248: }
249:
250: 251: 252: 253: 254: 255: 256:
257: static function scan($script, $valid = true) {
258: if ($script && $valid) {
259:
260: $result = query_full_array('SELECT * FROM ' . prefix('albums') . ' AS album,' . prefix('plugin_storage') . ' AS store WHERE store.type="galleryArticles" AND store.aux="pending_albums" AND store.data = album.folder AND album.date <= ' . db_quote(date('Y-m-d H:i:s')));
261: if ($result) {
262: foreach ($result as $album) {
263: query('DELETE FROM ' . prefix('plugin_storage') . ' WHERE `id`=' . $album['id']);
264: $album = newAlbum($album['folder']);
265: self::publishArticle($album);
266: }
267: }
268: $result = query_full_array('SELECT * FROM ' . prefix('images') . ' AS image,' . prefix('plugin_storage') . ' AS store WHERE store.type="galleryArticles" AND store.aux="pending_images" AND store.data LIKE image.filename AND image.date <= ' . db_quote(date('Y-m-d H:i:s')));
269: if ($result) {
270: foreach ($result as $image) {
271: query('DELETE FROM ' . prefix('plugin_storage') . ' WHERE `id`=' . $image['id']);
272: $album = query_single_row('SELECT * FROM ' . prefix('albums') . ' WHERE `id`=' . $image['albumid']);
273: $album = newAlbum($album['folder']);
274: $image = newImage($album, $image['filename']);
275: self::publishArticle($image);
276: }
277: }
278: }
279: return $script;
280: }
281:
282: }
283:
284: ?>