function photoshop_email_the_user($message, $subject, $admin = '') { global $CONFIG, $SHOP_CONFIG, $lang_photoshop, $cd_price, $order_id, $discount, $shipping_price; $user_info = photoshop_user_details(USER_ID); $email = $user_info['user_email']; if ($admin) { $user_info['user_email'] = 'admin'; } $template_vars = array('{ORDER_ID}' => $order_id, '{SITE_NAME}' => $CONFIG['gallery_name'], '{PRICE}' => number_format($cd_price[0] + $cd_price[1] + $shipping_price - $discount, 2), '{USER_NAME}' => USER_NAME, '{USER_EMAIL}' => $email, '{ADMIN}' => $CONFIG['gallery_name'], '{LINK}' => $CONFIG['ecards_more_pic_target'], '{USER_PROFILE1}' => $user_info['user_profile1'], '{USER_PROFILE2}' => $user_info['user_profile2'], '{USER_PROFILE3}' => $user_info['user_profile3'], '{USER_PROFILE4}' => $user_info['user_profile4'], '{USER_PROFILE5}' => $user_info['user_profile5'], '{USER_PROFILE6}' => $user_info['user_profile6']); $mail_body = nl2br(strtr($message, $template_vars)); if (cpg_mail($user_info['user_email'], $subject, $mail_body, 'text/plain', $CONFIG['gallery_name'], $CONFIG['gallery_admin_email'])) { return true; } return false; }
function photo_shop_ipn_download($uid, $oid, $mail_admin = false, $overwrite_dir = false) { global $CONFIG, $ERROR, $lang_photoshop_htaccess, $lang_photoshop_ipn_email_user, $lang_photoshop_index, $lang_photoshop_ipn, $template_index_html; //now create a download directory //first test if dir 'albums/downloads exists' if (!is_dir($CONFIG['fullpath'] . 'downloads')) { $cpg_umask = umask(0); @mkdir($CONFIG['fullpath'] . 'downloads', octdec($CONFIG['default_dir_mode'])); umask($cpg_umask); unset($cpg_umask); } //then create the dir for the user user-id_order-id //but first do some checks - safe mode enabled? downloads dir exists - if not create if (!defined('SILLY_SAFE_MODE')) { $filepath = 'downloads/' . $uid . '_' . $oid; $dest_dir = $CONFIG['fullpath'] . $filepath; if (!is_dir($dest_dir)) { mkdir($dest_dir, octdec($CONFIG['default_dir_mode'])); if (!is_dir($dest_dir)) { //couldn't create dir $ERROR = $lang_photoshop_ipn['ipn_download_err_mkdir']; return false; } //redundant but... hmmm @chmod($dest_dir, octdec($CONFIG['default_dir_mode'])); //silence the output in case chmod is disabled } elseif (!$overwrite_dir) { //directory exists return false; } $dest_dir .= '/'; $filepath .= '/'; //create random password... we use the users username for the htpasswd $clear_txt_password = photo_shop_gen_passwd(8); //$CTP = &$clear_txt_password; //if server os is windows, then we have to use plain passwords, *nix we need to crypt //so do the OS check now and then use wither crypted or plain pwd $htpasswd_path = getcwd() . '/' . $dest_dir; if (eregi("win", $_ENV['OS'])) { //win $password = $clear_txt_password; } else { //*nix)) $password = crypt($clear_txt_password, base64_encode($clear_txt_password)); } $user_info = photoshop_user_details($uid); // grab user_info, now we have username and his email addy (for now we use the name for the htpasswd) $order_hash = md5($uid . $oid . $password . $user_info['user_email']); //update shop table with hash $results = cpg_db_query("UPDATE {$CONFIG['TABLE_SHOP']} SET order_md5_id='{$order_hash}' WHERE oid='{$oid}' AND cd='1'"); //placeholder <-> path $template_vars = array('{HTPASSWD_PATH}' => $htpasswd_path . '.htpasswd'); $htaccess = strtr($lang_photoshop_htaccess, $template_vars); //get the filenames //query the path.filename of the order -> used to create the index.php in the downloads folder. When called that file will copy (resize) the images into the download dir //that way we reduce heat (timeouts) on the IPN script $sql = 'SELECT s.size2, p.filepath, p.filename, p.filesize, p.pwidth, p.pheight, p.title FROM ' . $CONFIG['TABLE_PICTURES'] . ' as p LEFT JOIN ' . $CONFIG['TABLE_SHOP'] . ' as s ON p.pid=s.pid WHERE oid=' . $oid . ' AND cd<>1'; $result = cpg_db_query($sql); $row = cpg_db_fetch_rowset($result); mysql_free_result($result); //write htpasswd $fp = fopen($dest_dir . '.htpasswd', 'w'); fwrite($fp, $user_info['user_name'] . ':' . $password); fclose($fp); //write htaccess $fp = fopen($dest_dir . '.htaccess', 'w'); fwrite($fp, $htaccess); fclose($fp); //write an index.html $fp = fopen($dest_dir . 'index.html', 'w'); fwrite($fp, " "); fclose($fp); //check if all worked if (is_file($dest_dir . 'index.html') && is_file($dest_dir . '.htpasswd') && is_file($dest_dir . '.htaccess')) { //when the files have been created and verified it's a good time to add the timestamp for automatic deletion of the folder after its lifespan $time = localised_timestamp(); $results = cpg_db_query("UPDATE {$CONFIG['TABLE_SHOP']} SET dtime='{$time}' WHERE oid='{$oid}' AND cd='1'"); //send user the password photo_shop_send_password($lang_photoshop_ipn_email_user, $lang_photoshop_ipn['ipn_email_user_subject'], $clear_txt_password, $user_info['user_name'], $user_info['user_email'], $order_hash); if ($mail_admin) { photo_shop_send_password($lang_photoshop_ipn_email_user, "{$lang_photoshop_ipn['ipn_email_admin_subject']} {$oid}", $clear_txt_password, $user_info['user_name'], 'admin', $order_hash); } $ERROR = $lang_photoshop_ipn['ipn_download_ok']; return true; } else { $ERROR = $lang_photoshop_ipn['ipn_download_err_noindex']; return false; } } else { //email admin safe mode restrictions and die $ERROR = $lang_photoshop_ipn['ipn_download_err_safemode']; return false; } }