/** * Updated a user's email * @param string $newEmail * @throws \Simplon\Mysql\MysqlException */ public function updateEmail($newEmail) { $this->db->update('aca_user', array('id' => $this->session->get('user_id')), array('email' => $newEmail)); }
/** * Updates the quantity of a product in the cart. * @param int $cartProductID * @param int $newQty * @return bool * @throws \Simplon\Mysql\MysqlException */ public function updateProductQty($cartProductID, $newQty) { return $this->db->update('aca_cart_product', array('id' => $cartProductID), array('quantity' => $newQty)); }
// Get the newest posted article // $article = $db->fetchRow("\n SELECT \n * \n FROM \n jobarticles\n WHERE \n post_id > 0\n AND \n sent_at IS NULL\n ORDER BY \n date DESC\n LIMIT 1\n"); if (!$article) { echo "no articles to send"; exit; } // // Preparing Article for inserting in article // $letter_template = file_get_contents('letter_template.html'); $content_full = $article['content']; $cut_pos = strpos(strip_tags($content_full), ' ', 330); $content_short = substr(strip_tags($content_full), 0, $cut_pos); $article_url = get_permalink($article['post_id']); $content_short_html = sprintf('<h3>%s</h3><p>%s... <a href="%s">%s</a></p>', $article['title'], $content_short, $article_url, 'Read full article on WorkHomeToday.net'); $content_html = str_replace("%article%", $content_short_html, $letter_template); $content_text = sprintf('%s... Read full article on WorkHomeToday.net: %s', $content_short, $article_url); // Mailgun Instance $MG = new Mailgun(MG_KEY); // Mailgun send message $sendingdata = array('from' => sprintf('Work Home Today <%s>', NEWS_EMAIL), 'to' => sprintf("%s@%s", 'daily', MG_DOMAIN), 'subject' => $article['title'], 'html' => $content_html, 'text' => $content_text, 'o:tag' => 'testletters'); $result = $MG->sendMessage(MG_DOMAIN, $sendingdata); // if message sent - prepare sql for updating prediction if (MG_SENDMSG_OK_MSG == $result->http_response_body->message) { echo "Sent OK"; $db->update('jobarticles', array('id' => $article['id']), array('sent_at' => date('Y-m-d H:i:s'))); echo " Updated OK"; } else { echo "<span style='color:red'>Something went WRONG</span>"; }
/** * Update a product in the cart * @param int $productId * @param int $quantity * @param int $cartId * @return bool */ public function updateProduct($productId, $quantity, $cartId) { $this->db->update('aca_cart_product', array('product_id' => $productId, 'cart_id' => $cartId), array('quantity' => $quantity)); }
if (!$article) { echo "no articles to post"; exit; } // // Post this article $post_id = -1; // Setup the author, slug, and title for the post $slug = $article['source_id'] . '_' . slugify($article['title']); $title = $article['title']; // If the page doesn't already exist, then create it if (null == get_page_by_title($article['title'])) { $post_data = ['comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => POST_AUTHOR_ID, 'post_name' => $slug, 'post_title' => $title, 'post_status' => 'publish', 'post_type' => 'post', 'post_content' => $article['content']]; // Set the page ID so that we know the page was created successfully $post_id = wp_insert_post($post_data); $db->update('jobarticles', array('id' => $article['id']), array('post_id' => $post_id, 'published_at' => date('Y-m-d H:i:s'))); // Attach featured image // First, we need to download the featured img $image_url = $article['featured_img']; $upload_dir = wp_upload_dir(); $image_data = file_get_contents($image_url); $filename = basename($image_url); $file = wp_mkdir_p($upload_dir['path']) ? sprintf("%s/%s", $upload_dir['path'], $filename) : sprintf("%s/%s", $upload_dir['basedir'], $filename); // upload file_put_contents($file, $image_data); $wp_filetype = wp_check_filetype($filename, null); $attachment = ['post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($filename), 'post_content' => '', 'post_status' => 'inherit']; // attach to the post $attach_id = wp_insert_attachment($attachment, $file, $post_id); require_once ABSPATH . 'wp-admin/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $file);