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