Skip to content
This repository has been archived by the owner. It is now read-only.

CLAS Update #4

Merged
merged 4 commits into from May 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
246 changes: 168 additions & 78 deletions functions.php
Expand Up @@ -7,10 +7,19 @@ February 2014
by UITS Web Lab brian.dunnigan@uconn.edu

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
function new_excerpt_more( $more ) {
return ' <a class="read-more" href="' . get_permalink( get_the_ID() ) . '">Read More</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );

function custom_excerpt_length( $length ) {
return 200;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );


add_theme_support( 'post-thumbnails' );

add_theme_support( 'post-thumbnails' );

// If no Menu is created, displays a home link, and starts listing pages across the top.

Expand Down Expand Up @@ -204,10 +213,6 @@ function my_cpt_post_types( $post_types ) {

add_filter( 'cpt_post_types', 'my_cpt_post_types' );





/*
Disabled until theme supports these types... (AB June 26, 2013)
add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
Expand Down Expand Up @@ -306,9 +311,9 @@ function hale_enqueue_scripts() {
}
add_action('wp_enqueue_scripts', 'hale_enqueue_scripts');

add_action( 'wp_ajax_clas_post_content', 'prefix_ajax_clas_post_content' );
add_action('wp_ajax_nopriv_clas_post_content', 'prefix_ajax_clas_post_content');
function prefix_ajax_clas_post_content() { //Retrieves post info and content for ajax on News-Archive
add_action( 'wp_ajax_clas_post_content', 'ajax_clas_post_content' );
add_action('wp_ajax_nopriv_clas_post_content', 'ajax_clas_post_content');
function ajax_clas_post_content() { //Retrieves post info and content for ajax on News-Archive
$id = $_POST['postID'];
global $post;
$content_post = get_post($id);
Expand All @@ -331,100 +336,185 @@ function prefix_ajax_clas_post_content() { //Retrieves post info and content for
echo wp_json_encode($object);
die();
}
add_action( 'wp_ajax_clas_tag_posts', 'prefix_ajax_clas_tag_posts' );
add_action('wp_ajax_nopriv_clas_tag_posts', 'prefix_ajax_clas_tag_posts');
function prefix_ajax_clas_tag_posts() { //Retieves posts of a specific tag, using class name
$tag = $_POST['val'];
$args = "tag='".$tag."'&orderby=post-date&field=ids&numberposts=-1";
$ids = get_posts( $args );
if( $tag == 'All News' ){
$ids = get_posts( 'orderby=post-date&field=ids&numberposts=-1' );

function getPostExcerpt( $id ){
$content = get_post($id)->post_content;
$excerpt = strip_tags( strip_shortcodes( $content ) );
$words = explode(' ', $excerpt, 201);

if(count($words) > 200){
array_pop($words);
array_push($words, '…');
$excerpt = implode(' ', $words);
}

$excerpt = '<p>'.$excerpt.'</p>';

return $excerpt;
}

function getPostSlug( $id ){
return get_post($id)->post_name;
}

add_action( 'wp_ajax_clas_posts', 'ajax_clas_posts' );
add_action('wp_ajax_nopriv_clas_posts', 'ajax_clas_posts');
function ajax_clas_posts(){
$posts = $_POST['postIDs'];
$postObj = new stdClass();
if( !empty($posts) ){
foreach( $posts as $k=>$id ){
$postObj->$k = new stdClass();
$postObj->$k->id = $id;
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->excerpt = getPostExcerpt($id);
$postObj->$k->date = get_the_time('F j, Y', $id);
$postObj->$k->featuredImage = get_the_post_thumbnail($id, 'medium', $attr);
}
$json = wp_json_encode( $postObj );
}
$object = new stdClass();
foreach( $ids as $k=>$id ){
$link = get_permalink($id);
$title = get_the_title($id);
$object->$k->link = $link;
$object->$k->title = $title;
$object->$k->postID = $id;

echo $json;
wp_die();
}

add_action( 'wp_ajax_clas_tag_posts', 'ajax_clas_tag_posts' );
add_action('wp_ajax_nopriv_clas_tag_posts', 'ajax_clas_tag_posts');
function ajax_clas_tag_posts() { //Retieves posts of a specific tag, using class name
$tag = $_POST['tag'];

$args = array(
'numberposts' => -1,
'fields' => 'ids'
);
if( $tag !== 'all-divisions' ){
$args['tag'] = $tag;
}
echo wp_json_encode($object);
die();

$posts = get_posts( $args );

if( !empty($posts) ){
$postObj = new stdClass();
foreach( $posts as $k=>$id ){
$postObj->$k = new stdClass();
$postObj->$k->id = $id;
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
}
$json = wp_json_encode( $postObj );
}

echo $json;
wp_die();
}

add_action( 'wp_ajax_clas_cat_posts', 'prefix_ajax_clas_cat_posts' );
add_action('wp_ajax_nopriv_clas_cat_posts', 'prefix_ajax_clas_cat_posts');
function prefix_ajax_clas_cat_posts() { //Retieves posts of a specific category or tag, using cat/tag id
$json = $_POST['data'];
$tax = $json['taxonomy'];
$val = $json['value'];
add_action( 'wp_ajax_clas_cat_posts', 'ajax_clas_cat_posts' );
add_action('wp_ajax_nopriv_clas_cat_posts', 'ajax_clas_cat_posts');
function ajax_clas_cat_posts() { //Retieves posts of a specific category or tag, using cat/tag id
$tax = $_POST['taxonomy'];
$val = $_POST['value'];

$args = array(
'field' => 'ids',
'numberposts' => -1
);

if( $tax == 'category' ){
$args = "category='".$val."'&orderby=post-date&field=ids&numberposts=-1";
$taxName = get_cat_name($val);
$args['cat'] = $val;
//$taxName = get_cat_name($val);
} else if( $tax == 'tag' ) {
$args = "tag_id=".$val."&orderby=post-date&field=ids&numberposts=-1";
$taxName = get_term_by( 'id', $val, 'post_tag' )->slug;
$args['tag_id'] = $val;
//$taxName = get_tag($val)->name;
}

$ids = get_posts( $args );
if( $val == "0" ){
$ids = get_posts( 'category=19&orderby=post-date&field=ids&numberposts=-1' );
}
$object = new stdClass();
foreach( $ids as $k=>$id ){
$link = get_permalink($id);
$title = get_the_title($id);
$object->$k->link = $link;
$object->$k->title = $title;
$object->$k->postID = $id;
$object->$k->taxName = $taxName;

$posts = get_posts( $args );

$postObj = new stdClass();
foreach( $posts as $k=>$id ){
$postObj->$k = new stdClass();
$postObj->$k->id = $id->ID;
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
}
echo wp_json_encode($object);
die();
echo wp_json_encode($postObj);
wp_die();
}

add_action( 'wp_ajax_clas_search_archive', 'prefix_ajax_clas_search_archive' );
add_action('wp_ajax_nopriv_clas_search_archive', 'prefix_ajax_clas_search_archive');
function prefix_ajax_clas_search_archive() { //Retieves posts of a specific category or tag, using cat/tag id
add_action( 'wp_ajax_clas_search_archive', 'ajax_clas_search_archive' );
add_action('wp_ajax_nopriv_clas_search_archive', 'ajax_clas_search_archive');
function ajax_clas_search_archive() { //Retieves posts of a specific category or tag, using cat/tag id
$search = $_POST['search'];

$archiveQuery = new WP_Query( 'category_name=archive&fields=ids&s='.$search.'' );
$args = array(
's' => $search,
'fields' => 'ids',
'category_name' => 'archive'
);
$archiveQuery = new WP_Query( $args );
$archivePosts = $archiveQuery->get_posts();
$object = new stdClass();

$postObj = new stdClass();
foreach( $archivePosts as $k=>$id ){
if( in_array($id, $archivePosts) ){
$link = get_permalink($id);
$title = get_the_title($id);
$object->$k->link = $link;
$object->$k->title = $title;
$object->$k->postID->ID = $id;
$postObj->$k = new stdClass();
$postObj->$k->id = $id;
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
}
}

echo wp_json_encode($object);
die();
echo wp_json_encode( $postObj );
wp_die();
}

add_action( 'wp_ajax_clas_orderby_posts', 'prefix_ajax_clas_orderby_posts' );
add_action('wp_ajax_nopriv_clas_orderby_posts', 'prefix_ajax_clas_orderby_posts');
function prefix_ajax_clas_orderby_posts() { //Retrieves and sorts posts by date
$json = $_POST['info'];
$order = $json['order'];
$ids = $json['posts'];
$args = array( 'include' => $ids, 'order'=> $order, 'orderby' => 'post-date', 'field' => 'ids', 'numberposts' => -1 );
//$args = "order=".$order."&include[]=".$ids."&orderby=post-date&field=ids&numberposts=-1";
add_action( 'wp_ajax_clas_orderby_posts', 'ajax_clas_orderby_posts' );
add_action('wp_ajax_nopriv_clas_orderby_posts', 'ajax_clas_orderby_posts');
function ajax_clas_orderby_posts() { //Retrieves and sorts posts by date
$info = $_POST['info'];
$order = $info['order'];
$ids = $info['posts'];

$args = array(
'include' => $ids,
'order'=> $order,
'field' => 'ids',
'numberposts' => -1
);
$posts = get_posts( $args );
$object = new stdClass();

$postObj = new stdClass();
foreach( $posts as $k=>$id ){
$link = get_permalink($id);
$title = get_the_title($id);
$object->$k->link = $link;
$object->$k->title = $title;
$object->$k->postID = $id;
$postObj->$k = new stdClass();
$postObj->$k->id = $id->ID;
$postObj->$k->slug = getPostSlug($id);
$postObj->$k->link = get_permalink($id);
$postObj->$k->title = get_the_title($id);
}
echo wp_json_encode($object);
die();
echo wp_json_encode($postObj);
wp_die();
}

add_action( 'wp_ajax_clas_taxid', 'ajax_clas_taxid' );
add_action('wp_ajax_nopriv_clas_taxid', 'ajax_clas_taxid');
function ajax_clas_taxid(){
$taxonomyName = $_POST['taxonomyName'];
$taxonomyType = $_POST['taxonomyType'];

if( $taxonomyType == 'category' ){
$idObj = get_category_by_slug($taxonomyName);
$id = $idObj->term_id;
} else if( $taxonomyType == 'tag' ) {
$idObj = get_term_by('slug', $taxonomyName, 'post_tag');
$id = $idObj->term_id;
}

echo wp_json_encode( $id );
wp_die();
}

function huskypress_customize_register( $wp_customize )
Expand Down