My first answer focused on how to define the basis functions themselves; however, that didn't answer your question. Here I will describe how that relates to the mass/stiffness matrices.
Background
I'm going to explain how to build a mass matrix based on a continuous Galerkin approach to the finite element method using the 1D diffusion problem as an example:
$$ \nabla^2 \phi - f = 0$$
A quick step back into the FEM formulation, we want to convert our problem into a finite element problem. We start by making the assumption that we can represent the true solution by only using a finite number of nodes. We'll call the true solution $ \phi$ and the finite element solution $\hat{\phi}$. Our solution probably won't be perfect because of the approximation, but it'll be good enough. Another way of saying that is by calling it a residual:
$$\mathcal{R}\left( \hat{\phi} \right) = \nabla^2\hat{\phi} -f \cong 0 $$
We're now going to multiply our residual function with our finite element test functions, integrate that over the domain, and set the integral to zero (excellent analogy for why here). We end up with this statement:
$$ \int_\Omega \underline{N} \mathcal{R} \left( \hat{\phi} \right) \partial \Omega = \int_\Omega \underline{N} \left( \nabla^2\hat{\phi} -f \right) \partial \Omega = 0 $$
or
$$ \int_\Omega \underline{N} \left( \nabla^2\hat{\phi} \right) \partial \Omega = \int_\Omega \underline{N} \left( f \right) \partial \Omega $$
$\underline{N}$ is a vector of basis functions (length = number of nodes) used to discretize the system. $\hat{\phi}$ is the approximate solution to our problem, which is interpolated by a polynomial within each element. For the linear case, traversing along the element $s$ = [-1 1]:
$$ \hat{\phi}(s) = N_1(s)\tilde{\phi}_1 + N_2(s)\tilde{\phi}_2 = \underline{N}^T \underline{\tilde{\phi}}$$
Likewise, for the quadratic case:
$$ \hat{\phi}(s) = N_1(s)\tilde{\phi}_1 + N_2(s)\tilde{\phi}_2 + N_3(s)\tilde{\phi}_3 = \underline{N}^T \underline{\tilde{\phi}}$$
We're going to discretize the domain using 3 linear elements ($l_{1-3}$), which results in 4 nodes ($\tilde{\phi}_{1-4}$). Let's also assume we have Dirichlet boundaries at the ends $(\tilde{\phi}_{1} = \tilde{\phi}_{L} ~,~ \tilde{\phi}_{4} = \tilde{\phi}_{R})$:

It's common to construct the mass matrix in a block pattern, where we first create an elemental mass matrix corresponding to each element, and then fill it into the global mass matrix. Therefore, we are going to isolate our original equation to the first element:
$$ \int_{\Omega_1} \underline{N} \left( \nabla^2\hat{\phi} \right) \partial \Omega_1 = \int_{\Omega_1} \underline{N} \left( f \right) \partial \Omega_1 $$
And we are going to replace $\hat{\phi}$ with $\underline{N}^T \underline{\tilde{\phi}}$:
$$ \int_{\Omega_1} \underline{N} \left( \nabla^2 (\underline{N}^T \underline{\tilde{\phi}}) \right) \partial \Omega_1 = \int_{\Omega_1} \underline{N} \left( f \right) \partial \Omega_1 $$
Now I'm not going to go into these steps, but needless to say we can use integration by parts to convert the second derivative into a first derivative, after which you end up with this:
$$ \int_{\Omega_1} \frac{\partial\underline{N}}{\partial x} \frac{\partial\underline{N}^T}{\partial x} \underline{\tilde{\phi}} \partial \Omega_1 = \int_{\Omega_1} \underline{N} \left( f \right) \partial \Omega_1 $$
The answer to your question
Now I think you're asking, how do you turn this integral into an elemental matrix, which you are later going to add to the global matrix. And specifically, what is the influence of nodes using basis functions of higher order than 1? Well, going back to the linear element case, there are two nodes per element. That means the size of $\underline{N}$ is $(2,1)$. The resulting elemental block matrix is then:
$$
\left[ \begin{matrix}
\int_{\Omega_1} \frac{\partial N_1}{\partial x} \frac{\partial N_1}{\partial x} \partial \Omega_1 & \int_{\Omega_1} \frac{\partial N_1}{\partial x} \frac{\partial N_2}{\partial x} \partial \Omega_1 \\
\int_{\Omega_1} \frac{\partial N_2}{\partial x} \frac{\partial N_1}{\partial x} \partial \Omega_1 & \int_{\Omega_1} \frac{\partial N_2}{\partial x} \frac{\partial N_2}{\partial x} \partial \Omega_1 \\
\end{matrix} \right]
$$
For a quadratic element, there are 3 nodes. The resulting elemental block matrix has to reflect that, and is:
$$
\left[ \begin{matrix}
\int_{\Omega_1} \frac{\partial N_1}{\partial x} \frac{\partial N_1}{\partial x} \partial \Omega_1 & \int_{\Omega_1} \frac{\partial N_1}{\partial x} \frac{\partial N_2}{\partial x} \partial \Omega_1 & \int_{\Omega_1} \frac{\partial N_1}{\partial x} \frac{\partial N_3}{\partial x} \partial \Omega_1 \\
\int_{\Omega_1} \frac{\partial N_2}{\partial x} \frac{\partial N_1}{\partial x} \partial \Omega_1 & \int_{\Omega_1} \frac{\partial N_2}{\partial x} \frac{\partial N_2}{\partial x} \partial \Omega_1 & \int_{\Omega_1} \frac{\partial N_2}{\partial x} \frac{\partial N_3}{\partial x} \partial \Omega_1 \\
\int_{\Omega_1} \frac{\partial N_3}{\partial x} \frac{\partial N_1}{\partial x} \partial \Omega_1 & \int_{\Omega_1} \frac{\partial N_3}{\partial x} \frac{\partial N_2}{\partial x} \partial \Omega_1 & \int_{\Omega_1} \frac{\partial N_3}{\partial x} \frac{\partial N_3}{\partial x} \partial \Omega_1 \\
\end{matrix} \right]
$$