} } $user_args = $args; if (isset($authkey)) { $user_args['auth_key'] = $authkey['auth_key']; } switch_lang_to($u['language']); pwg_mail($u['email'], $user_args, $user_tpl); switch_lang_back(); } $message = l10n_dec('%d mail was sent.', '%d mails were sent.', count($users)); $message .= ' (' . implode(', ', $usernames) . ')'; $page['infos'][] = $message; } elseif ('group' == $_POST['who'] and !empty($_POST['group'])) { check_input_parameter('group', $_POST, false, PATTERN_ID); pwg_mail_group($_POST['group'], $args, $tpl); $query = ' SELECT name FROM ' . GROUPS_TABLE . ' WHERE id = ' . $_POST['group'] . ' ;'; list($group_name) = pwg_db_fetch_row(pwg_query($query)); $page['infos'][] = l10n('An information email was sent to group "%s"', $group_name); } unset_make_full_url(); } // +-----------------------------------------------------------------------+ // | template initialization | // +-----------------------------------------------------------------------+ $template->set_filename('album_notification', 'album_notification.tpl');
function pfemail_check_accounts() { global $conf, $user; conf_update_param('pfemail_last_check', date('Y-m-d H:i:s')); require_once PFEMAIL_PATH . 'include/ImapMailbox.php'; $image_ids = array(); $query = ' SELECT * FROM ' . PFEMAIL_MAILBOXES_TABLE . ' ;'; $accounts = query2array($query); foreach ($accounts as $account) { $mailbox = new ImapMailbox($account['path'], $account['login'], $account['password'], $conf['upload_dir'] . '/buffer', 'utf-8'); $mails = array(); // Get some mail $mailsIds = $mailbox->searchMailBox('UNSEEN'); if (!$mailsIds) { continue; // check next email account } $mailId = reset($mailsIds); $mail = $mailbox->getMail($mailId); $attachments = $mail->getAttachments(); include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'; foreach ($attachments as $attachment) { $extension = strtolower(get_extension($attachment->{'name'})); if (!in_array($extension, $conf['picture_ext'])) { // the file has been downloaded, we have to remove it now unlink($attachment->{'filePath'}); continue; } $moderate = get_boolean($account['moderated']); $image_id = add_uploaded_file($attachment->{'filePath'}, stripslashes($attachment->{'name'}), array($account['category_id']), $moderate ? 16 : 0, null); // the photo is added by nobody (using the current user may make the // photo editable by her with Admin Tools...) single_update(IMAGES_TABLE, array('added_by' => null, 'name' => pfemail_clean_email_subject($mail->subject)), array('id' => $image_id)); $state = 'auto_validated'; if ($moderate) { $state = 'moderation_pending'; } list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); single_insert(PFEMAIL_PENDINGS_TABLE, array('image_id' => $image_id, 'state' => $state, 'added_on' => $dbnow, 'from_name' => $mail->fromName, 'from_address' => $mail->fromAddress, 'subject' => $mail->subject)); $image_ids[] = $image_id; } } if (count($image_ids) > 0) { include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; invalidate_user_cache(); // let's notify administrators $query = ' SELECT id FROM ' . GROUPS_TABLE . ' ;'; $group_ids = query2array($query, null, 'id'); if (count($group_ids) > 0) { include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'; $thumb_urls = array(); // force $conf['derivative_url_style'] to 2 (script) to make sure we // will use i.php?/upload and not _data/i/upload because you don't // know when the cache will be flushed $previous_derivative_url_style = $conf['derivative_url_style']; $conf['derivative_url_style'] = 2; $query = ' SELECT id, path FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $image_ids) . ') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $thumb = DerivativeImage::thumb_url(array('id' => $row['id'], 'path' => $row['path'])); $thumb_urls[] = $thumb; } // restore configuration setting $conf['derivative_url_style'] = $previous_derivative_url_style; $thumbs_html_string = ''; foreach ($thumb_urls as $thumb_url) { if (!empty($thumbs_html_string)) { $thumbs_html_string .= ' '; } $thumbs_html_string .= '<img src="' . $thumb_url . '">'; } $content = $thumbs_html_string; // how many photos pending? $pendings = pfemail_get_pending_ids(); if (count($pendings) > 0) { $content .= '<br><br>'; $content .= '<a href="' . get_absolute_root_url() . 'admin.php?page=plugin-photo_from_email-pendings' . '">'; $content .= l10n('%d photos pending for validation', count($pendings)); $content .= '</a>'; } $real_user_id = $user['id']; $user['id'] = $conf['guest_id']; $subject = l10n('%d photos added by email', count($thumb_urls)); foreach ($group_ids as $group_id) { pwg_mail_group($group_id, array('subject' => '[' . $conf['gallery_title'] . '] ' . $subject, 'mail_title' => $conf['gallery_title'], 'mail_subtitle' => $subject, 'content' => $content, 'content_format' => 'text/html')); } } // restore current user $user['id'] = $real_user_id; } }
if (!empty($category['representative_picture_id'])) { $query = ' SELECT id, file, path, representative_ext FROM ' . IMAGES_TABLE . ' WHERE id = ' . $category['representative_picture_id'] . ' ;'; $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { $element = pwg_db_fetch_assoc($result); $img_url = '<a href="' . make_picture_url(array('image_id' => $element['id'], 'image_file' => $element['file'], 'category' => $category)) . '" class="thumblnk"><img src="' . DerivativeImage::url(IMG_THUMB, $element) . '"></a>'; } } if (!isset($img_url)) { $img_url = ''; } pwg_mail_group($_POST['group'], array('subject' => l10n('[%s] Visit album %s', $conf['gallery_title'], trigger_change('render_category_name', $category['name'], 'admin_cat_list'))), array('filename' => 'cat_group_info', 'assign' => array('IMG_URL' => $img_url, 'CAT_NAME' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'LINK' => make_index_url(array('category' => array('id' => $category['id'], 'name' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'permalink' => $category['permalink']))), 'CPL_CONTENT' => empty($_POST['mail_content']) ? '' : stripslashes($_POST['mail_content'])))); unset_make_full_url(); $query = ' SELECT name FROM ' . GROUPS_TABLE . ' WHERE id = ' . $_POST['group'] . ' ;'; list($group_name) = pwg_db_fetch_row(pwg_query($query)); $page['infos'][] = l10n('An information email was sent to group "%s"', $group_name); } // +-----------------------------------------------------------------------+ // | template initialization | // +-----------------------------------------------------------------------+ $template->set_filename('album_notification', 'album_notification.tpl'); $template->assign(array('CATEGORIES_NAV' => get_cat_display_name_from_id($page['cat'], 'admin.php?page=album-'), 'F_ACTION' => $admin_album_base_url . '-notification', 'PWG_TOKEN' => get_pwg_token()));