/** * Add the image for gravatar * * @param string $file * @param string $path * @return array [name (the name of the file), image (the path of the image), message (the returned message)] * */ public function addImage($file, $path = ABSPATH) { $out = array(); $out['name'] = strtolower(basename($file['name'])); $out['gravatar'] = _ABH_GRAVATAR_DIR_ . strtolower(basename($file['name'])); $out['message'] = ''; $file_error = $file['error']; $img = new Model_ABH_Image(); /* get the file extension */ $file_name = explode('.', $file['name']); $file_type = strtolower($file_name[count($file_name) - 1]); /* if the file has a name */ if (!empty($file['name'])) { /* Check the extension */ $file_type = strtolower($file_type); $files = array('jpeg', 'jpg', 'gif', 'png'); $key = in_array($file_type, $files); if (!$key) { ABH_Classes_Error::setError(__("File type error: Only JPEG, JPG, GIF or PNG files are allowed.", _ABH_PLUGIN_NAME_)); return; } /* Check for error messages */ $error_count = count($file_error); if (!empty($file_error) && $error_count > 0) { for ($i = 0; $i <= $error_count; ++$i) { ABH_Classes_Error::setError($file['error'][$i]); return; } } elseif (!$img->checkFunctions()) { ABH_Classes_Error::setError(__("GD error: The GD library must be installed on your server.", _ABH_PLUGIN_NAME_)); return; } else { /* Delete the previous file if exists */ if (is_file($out['gravatar'])) { if (!unlink($out['gravatar'])) { ABH_Classes_Error::setError(__("Delete error: Could not delete the old gravatar.", _ABH_PLUGIN_NAME_)); return; } } /* Upload the file */ if (!move_uploaded_file($file['tmp_name'], $out['gravatar'])) { ABH_Classes_Error::setError(__("Upload error: Could not upload the gravatar.", _ABH_PLUGIN_NAME_), 'fatal'); return; } /* Change the permision */ if (!chmod($out['gravatar'], 0755)) { ABH_Classes_Error::setError(__("Permission error: Could not change the gravatar permissions.", _ABH_PLUGIN_NAME_)); return; } /* Transform the image into icon */ $img->openImage($out['gravatar']); $img->resizeImage(80, 80); $img->saveImage(); copy($img->image, $out['gravatar']); $out['message'] .= __("The gravatar has been updated.", _ABH_PLUGIN_NAME_); return $out; } } }
/** * This hook will show the error in WP header */ function hookNotices() { if (is_array(self::$errors)) { foreach (self::$errors as $error) { switch ($error['type']) { case 'fatal': self::showError(ucfirst(_ABH_PLUGIN_NAME_ . " " . $error['type']) . ': ' . $error['text'], $error['id']); die; break; case 'settings': /* switch off option for notifications */ self::$switch_off = "<a href=\"javascript:void(0);\" onclick=\"jQuery.post( ajaxurl, {action: 'abh_warnings_off', nonce: '" . wp_create_nonce('abh_none') . "'}, function(data) { if (data) { jQuery('#abh_ignore_warn').attr('checked', true); jQuery('.abh_message').hide(); jQuery('#toplevel_page_abh .awaiting-mod').fadeOut('slow'); } });\" >" . __("Turn off warnings!", _ABH_PLUGIN_NAME_) . "</a>"; self::showError(ucfirst(_ABH_PLUGIN_NAME_) . " " . __('Notice: ', _ABH_PLUGIN_NAME_) . $error['text'] . " " . self::$switch_off, $error['id']); break; default: self::showError(ucfirst(_ABH_PLUGIN_NAME_) . " " . __('Note: ', _ABH_PLUGIN_NAME_) . $error['text'], $error['id']); } } } self::$errors = array(); }
/** * Check for SEO blog bad settings */ public static function checkErrorSettings($count_only = false) { if (function_exists('is_network_admin') && is_network_admin()) { return; } if (false) { if ($count_only) { self::$errors_count++; } else { ABH_Classes_Error::setError(__('Notice', _ABH_PLUGIN_NAME_) . " <br /> ", 'settings'); } } }