Example #1
0
 * @linkedin: https://pt.linkedin.com/in/tiago-pais-2676234b
 */
//Setting up Environment
session_start();
//Start session to use the session vars
include dirname(__DIR__) . '/config/db_connect.php';
/**
 * Processing the Request
 */
//Getting the method
$request_method = $_SERVER['REQUEST_METHOD'];
//Filter the Request Method
switch ($request_method) {
    case 'POST':
        //Process New Entry
        addNewEntry();
        break;
    default:
        break;
}
//Setting session vars for Messages
$_SESSION['success'] = "";
//success messages
$_SESSION['errors'] = "";
//error messages
/**
 * Functions
 */
//Validate Requests
function validateRequest()
{
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
require_once 'config.php';
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['dbname'] . ';charset=utf8', $config['username'], $config['password']);
installDB($db, $config);
$array = simplexml_load_file($feed_url);
$new_entries = array();
foreach ($array->channel->item as $key => $item) {
    if (addNewEntry($db, $config, $feed_url, $item->link, $item->title, $item->guid)) {
        $new_entries[] = $item;
    }
}
if (count($new_entries) > 0 && count($receivers) > 0) {
    sendMail($receivers, $new_entries);
}
function addNewEntry($db, $config, $feed_url, $link, $title, $guid)
{
    try {
        $stmt = $db->prepare("INSERT INTO `" . $config['table'] . "` (feed_url, link, title, guid, created)\n\t\t\t\tVALUES(:feed_url, :link, :title, :guid, now())");
        if (!$stmt->execute(array(':feed_url' => $feed_url, ':link' => $link, ':title' => $title, ':guid' => $guid))) {
            $err = $stmt->errorInfo();
            if ($err[1] == 1062) {
                /* Dublicate entry - return false;*/
            }