Skip to content

Commit

Permalink
Added info about, developer, manufacturer, trl and license to components
Browse files Browse the repository at this point in the history
Improved tags visualisation
  • Loading branch information
antonio-goncalves-unp committed Dec 13, 2023
1 parent 547bce2 commit 510b656
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 30 deletions.
57 changes: 57 additions & 0 deletions includes/iotcat_components.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,63 @@ function join($wp_join) {
return ($wp_join);
}

protected function render_entity_names($entities){
if(gettype($entities)!== "array") return "";
$filtered_entities = array_filter($entities,function($var){
return array_key_exists("name", $var);
});

if(count($filtered_entities) === 0) return "";
$names_html = "";
for($i=0;$i<count($filtered_entities);$i++){
$name = $filtered_entities[$i]["name"];
$website = $filtered_entities[$i]["website"];
$name_html = "<a target=\"_blank\" href=\"$website\" >$name</a>";
$names_html = $names_html."$name_html";
if($i< count($filtered_entities) - 1){
$names_html = $names_html.", ";
}
}

return "
<div class=\"iotcat-element-info-box\">
<b class=\"label\">Developers</b>$names_html
</div>
";
}


protected function render_license_name($original_object){
if(!array_key_exists("_license", $original_object)) return "";
$license = $original_object["_license"];
return "
<div class=\"iotcat-element-info-box\">
<b class=\"label\">License</b>$license
</div>
";
}

protected function get_page_content($name,$description,$website,$embedded_url, $image_url,$tags_path,$original_object){
$trl = array_key_exists("_trl", $original_object) ?$original_object["_trl"]:"";
$trl_html = "";
if($trl != ""){
$trl_html ="<div class=\"iotcat-element-info-box\">
<b class=\"label\">TRL</b>$trl
</div>";
}

return
"<p>$description</p>".
"$trl_html".
$this->render_entity_names($original_object["_manufacturers"]).
$this->render_entity_names($original_object["_developers"]).
$this->render_license_name($original_object).
$this->get_tags_elements($tags_path).
$this->get_website_link($website);


}

function set_default_sort($orderby,&$query) {
global $wpdb;
if(get_query_var('post_type') == $this->post_type) {
Expand Down
73 changes: 46 additions & 27 deletions includes/iotcat_elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private function get_img_html($image_url){
return "";
}

private function get_website_link($website){
protected function get_website_link($website){

if(isset($website) && $website !== ""){

Expand Down Expand Up @@ -172,20 +172,23 @@ private function get_tags_input($tags_path){
return $tag_input;
}

private function get_tags_elements($tags_path){
protected function get_tags_elements($tags_path){

return "<div class=\"iotcat-tags-container-new mt-4\"><!-- wp:post-terms {\"term\":\"post_tag\",\"textAlign\":\"center\",\"separator\":\" \",\"style\":{\"typography\":{\"fontStyle\":\"normal\",\"fontWeight\":\"200\"}},\"fontSize\":\"medium\"} /--></div>";
//return "<div class=\"iotcat-tags-container-new mt-4\"><!-- wp:post-terms {\"term\":\"post_tag\",\"textAlign\":\"center\",\"separator\":\" \",\"style\":{\"typography\":{\"fontStyle\":\"normal\",\"fontWeight\":\"200\"}},\"fontSize\":\"medium\"} /--></div>";
$html = "";
if(isset($tags_path) && $tags_path !== null){
$tag_elements = array();
foreach($tags_path as $tag_path){
if(count($tag_path)>0){
$tag_name = $tag_path[0]["name"];
$tag =array("name"=> $tag_path[0]["name"]);
if(count($tag_path) > 1){
$tag["parent"] = $tag_path[1]["name"];
}
$tag_type_name = $tag_path[0]["typeName"];
if(!array_key_exists($tag_type_name,$tag_elements)){
$tag_elements[$tag_type_name] = array();
}
array_push($tag_elements[$tag_type_name],$tag_name);
array_push($tag_elements[$tag_type_name],$tag);

}

Expand All @@ -194,10 +197,16 @@ private function get_tags_elements($tags_path){
asort($tag_type_names);
foreach($tag_type_names as $tag_type_name){
$tags_html = "";
$tag_names = $tag_elements[$tag_type_name];
asort($tag_names);
foreach($tag_names as $tag_name){
$tags_html = $tags_html."<span class=\"iotcat-element-tag\">$tag_name</span>";
$tags = $tag_elements[$tag_type_name];

//asort($tag_names);
foreach($tags as $tag){
$parent = "";
if(array_key_exists("parent",$tag)){
$parent = "<span class=\"iotcat-element-tag-parent\">".$tag["parent"]."</span>";
}

$tags_html = $tags_html."<span class=\"iotcat-element-tag\">".$parent.$tag["name"]."</span>";
}
if($tags_html !== ""){
$html = $html."
Expand All @@ -212,14 +221,21 @@ private function get_tags_elements($tags_path){
}


protected function get_page_content($name,$description,$website,$embedded_url, $image_url,$tags_path){

$url = $this->should_post_process_iframe_url?"":$embedded_url;

protected function get_page_content($name,$description,$website,$embedded_url, $image_url,$tags_path,$original_object){
return
"<p>$description</p>".
$this->get_tags_elements($tags_path).
$this->get_website_link($website).
$this->get_website_link($website);


}


protected function get_page_content_with_iframe($name,$description,$website,$embedded_url, $image_url,$tags_path,$original_object){

$url = $this->should_post_process_iframe_url?"":$embedded_url;
return
$this->get_page_content($name,$description,$website,$embedded_url, $image_url,$tags_path,$original_object).
"<iframe id=\"iotcat-iframe\" data-url=\"$embedded_url\" style=\"height: 0px;width: 100%\" src=\"$url\" ></iframe>";


Expand Down Expand Up @@ -259,13 +275,17 @@ public function add_page_header() {
}

.iotcat-element-tag {
border: 1px solid #cdced0;
color: #494949;
padding: 2px 5px;
margin-right: 5px;
border-radius: 2px;
border: 1px solid #cdced0;
color: #494949;
padding: 2px 5px;
margin-right: 5px;
border-radius: 2px;
}
.iotcat-element-tag-parent {
margin-right: 5px;
border-right: 1px solid #cdced0;
padding-right: 5px;
}

.iotcat-tags-container-new{
margin-bottom: 1rem;
}
Expand Down Expand Up @@ -392,8 +412,7 @@ public function delete_post($id){
wp_delete_post($id);
}

private function create_post_element($id, $name, $description,$website, $embedded_url, $image_url,$tags_path,$original_id,$subscription_id,$last_update_timestamp){

private function create_post_element($id, $name, $description,$website, $embedded_url, $image_url,$tags_path,$original_id,$subscription_id,$last_update_timestamp,$original_object){

$meta_input = array_merge(
$this->default_metadata,
Expand All @@ -408,7 +427,7 @@ private function create_post_element($id, $name, $description,$website, $embedde
$element = array(
'post_title' => $name,
'post_status' => 'publish',
'post_content' => $this->get_page_content($name,$description,$website,$embedded_url, $image_url,$tags_path),
'post_content' => $this->get_page_content_with_iframe($name,$description,$website,$embedded_url, $image_url,$tags_path,$original_object),
'tags_input' => $this->get_tags_input($tags_path),
'post_type' => $this->post_type,
'meta_input' => $meta_input
Expand Down Expand Up @@ -475,10 +494,10 @@ public function add_element_image($post_id,$url){
return $attach_id;
}

public function add_new_element($name,$description, $website, $embedded_url,$image_url,$tags_path,$original_id,$last_update_timestamp,$subscription_id, $insert_repeated = false){
public function add_new_element($name,$description, $website, $embedded_url,$image_url,$tags_path,$original_id,$last_update_timestamp,$subscription_id,$original_object, $insert_repeated = false){

if($insert_repeated || !$this->has_element($original_id)){
$id = wp_insert_post( $this->create_post_element(null, $name,$description,$website,$embedded_url,$image_url,$tags_path,$original_id,$subscription_id, $last_update_timestamp ) );
$id = wp_insert_post( $this->create_post_element(null, $name,$description,$website,$embedded_url,$image_url,$tags_path,$original_id,$subscription_id, $last_update_timestamp ,$original_object) );
$attachment_id = $this->add_element_image($id,$image_url);
if(!is_null($attachment_id)){
add_post_meta($id,"_image_attachment_id",$attachment_id );
Expand All @@ -488,10 +507,10 @@ public function add_new_element($name,$description, $website, $embedded_url,$ima
}
}

public function update_element($id,$name,$description,$website, $embedded_url,$image_url,$tags_path,$original_id,$last_update_timestamp,$subscription_id){
public function update_element($id,$name,$description,$website, $embedded_url,$image_url,$tags_path,$original_id,$last_update_timestamp,$subscription_id,$original_object){

iotcat_log_me("update $this->post_type $name");
return wp_update_post( $this->create_post_element($id, $name,$description,$website,$embedded_url,$image_url,$tags_path,$original_id,$subscription_id, $last_update_timestamp ) );
return wp_update_post( $this->create_post_element($id, $name,$description,$website,$embedded_url,$image_url,$tags_path,$original_id,$subscription_id, $last_update_timestamp ,$original_object) );
}

}
Expand Down
6 changes: 4 additions & 2 deletions includes/iotcat_subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ function($id_info){
array_key_exists("_tagsPath", $element) ?$element["_tagsPath"]:null,
array_key_exists("_id", $element) ?$element["_id"]:"",
array_key_exists("_lastUpdateTimestamp", $element) ? round( $element["_lastUpdateTimestamp"]/1000):0,
$this->id
$this->id,
$element
);
} catch (Exception $e) {
iotcat_log_me("Failed to update element");
Expand All @@ -106,7 +107,8 @@ function($id_info){
array_key_exists("_tagsPath", $element) ?$element["_tagsPath"]:null,
array_key_exists("_id", $element) ?$element["_id"]:"",
array_key_exists("_lastUpdateTimestamp", $element) ? round( $element["_lastUpdateTimestamp"]/1000):0,
$this->id
$this->id,
$element
);
}
} catch (Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Plugin Name: IoT Catalogue Integration
* Description: Display in WordPress content from IoT Catalogue
* Version: 1.9.1
* Version: 1.10.0-0
* Author: UNPARALLEL Innovation, Lda
* Author URI: https://www.unparallel.pt
*/
Expand Down

0 comments on commit 510b656

Please sign in to comment.