valid()) { if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) { return $aIt->key(); } $it->next(); } return false; } /** * Add contact form scripts and styles, only when short code is present in page/posts */ function awp_check_for_shortcode($posts,$shortcode) { if ( empty($posts) ) return $posts; // false because we have to search through the posts first $found = false; // search through each post foreach ($posts as $post) { // check the post content for the short code if ((stripos($post->post_content, $shortcode))!==false) { // we have found a post with the short code $found = true; } // stop the search break; } return $found; } /** * Converts value to boolean * * @param mixed $value * @return boolean */ function awp_to_boolean($value) { if (is_string($value)) { switch (strtolower($value)) { case '+': case '1': case 'y': case 'on': case 'yes': case 'true': case 'enabled': return true; case '-': case '0': case 'n': case 'no': case 'off': case 'false': case 'disabled': return false; } } return (boolean) $value; } function awp_date_compare($a, $b) { $t1 = strtotime($a['datetime']); $t2 = strtotime($b['datetime']); return $t1 - $t2; } function awp_creation_date_compare($a, $b) { $t1 = $a->creationDate; $t2 = $b->creationDate; return $t1 - $t2; } function awp_sort_by_sequence($a, $b) { return $a->sequenceNumber - $b->sequenceNumber; } /** * Pagination * * @param unknown_type $reload * @param unknown_type $page * @param unknown_type $tpages * @return unknown */ function awp_paginate($reload, $page, $tpages,$totalitems) { $firstlabel = "<<"; $prevlabel = "<"; $nextlabel = ">"; $lastlabel = ">>"; $out = '
'; $out .= ''.$totalitems.' items'; // first if($page>1) { $out.= "" . $firstlabel . "\n"; } else { $out.= "" . $firstlabel . "\n"; } // previous if($page==1) { $out.= "" . $prevlabel . "\n"; } elseif($page==2) { $out.= "" . $prevlabel . "\n"; } else { $out.= "" . $prevlabel . "\n"; } // current //$out.= "Page " . $page . " of " . $tpages . "\n"; $out .=' of '.$tpages.'  '; // next if($page<$tpages) { $out.= "" . $nextlabel . "\n"; } else { $out.= "" . $nextlabel . "\n"; } // last if($page<$tpages) { $out.= "" . $lastlabel . "\n"; } else { $out.= "" . $lastlabel . "\n"; } $out.= "
"; return $out; } /** * To Make Soap Call * * @param unknown_type $wsdl * @param unknown_type $function * @param unknown_type $params * @return unknown */ function getsoapCall($wsdl,$function,$params) { $client = new SoapClient($wsdl); try { $response = $client->__soapCall($function, array($params)); }catch(Exception $e){ return 'E_100'; // Exception echo $e->getMessage(); } return $response; } /** * LoadMemCache Methods. * * @param unknown_type $wsdl * @param unknown_type $key_publishdate * @param unknown_type $plugincall_key * @param unknown_type $method_publishdate * @param unknown_type $plugincall_function * @param unknown_type $publishdate_params * @param unknown_type $plugincall_params * @return unknown */ function getAllItemsWithMemcache($wsdl,$publishdate_key,$plugincall_key,$publishdate_function,$plugincall_function,$publishdate_params,$plugincall_params) { $publishdate_key = APPTIVO_SITE_KEY.$publishdate_key; $plugincall_key = APPTIVO_SITE_KEY.$plugincall_key; if(class_exists('Memcache')) { $mcache_obj = new AWP_Mcache_Util(); //Create Object in AWP_DataCache clss $mcacheconnect = $mcache_obj->connectmcache(); } else { $mcacheconnect = FALSE; } //To check if the MemCache is connected or not. if( $mcacheconnect ) { //"connected MemCache."; $awp_cache_publishdate = $mcache_obj->getdata($publishdate_key); if( empty($awp_cache_publishdate)) //Check the published date key value is set in memcahe or not. { $load_news_service = TRUE; } else { $publish_date = getsoapCall(APPTIVO_SITE_SERVICES,$publishdate_function,$publishdate_params); $publish_prevDate = $publish_date->return; if($publish_prevDate == $awp_cache_publishdate) { $response = $mcache_obj->getdata($plugincall_key); $load_news_service = FALSE; }else { $load_news_service = TRUE; } } if($load_news_service) { // "Load Services."; $response = getsoapCall($wsdl,$plugincall_function,$plugincall_params); $publish_date = getsoapCall(APPTIVO_SITE_SERVICES,$publishdate_function,$publishdate_params); $mcache_obj->storedata($plugincall_key,$response); $mcache_obj->storedata($publishdate_key,$publish_date->return); $awp_cache_publishdate = $mcache_obj->getdata($publishdate_key); } }else { // "MemCache is not connected.."; $response = getsoapCall($wsdl,$plugincall_function,$plugincall_params); } return $response; } /** * get ApptiovWordPress(awp) Templates * * @param unknown_type $dir * @param unknown_type $type == 'widget' => "Widget Templates" , $type == 'plugin' => "Plugin templates" * @return Template Array Lists. */ function get_awpTemplates($dir,$type) { $default_headers = array( 'Template Name' => 'Template Name', 'Template Type' => 'Template Type' ); $templates = array(); $dir_news = $dir; // Open a known directory, and proceed to read its contents if (is_dir($dir_news)) { if ($dh = opendir($dir_news)) { while (($file = readdir($dh)) !== false) { if ( substr( $file, -4 ) == '.php' ) { $plugin_data = get_file_data( $dir_news."/".$file, $default_headers, '' ); if(strlen(trim($plugin_data['Template Name'])) != 0 ) { if(strtolower(trim($plugin_data['Template Type'])) == 'widget' && strtolower($type) == 'widget' ) { $templates[$plugin_data['Template Name']] = $file; }else if(strtolower(trim($plugin_data['Template Type'])) == 'shortcode' && strtolower($type) == 'plugin') { $templates[$plugin_data['Template Name']] = $file; }else if(strtolower(trim($plugin_data['Template Type'])) == 'inline' && strtolower($type) == 'inline') { $templates[$plugin_data['Template Name']] = $file; } } } } closedir($dh); } } return $templates; } /** * Remove html tags from string * * @param string $str * @return string */ function html_remove($str){ return $str; return preg_replace("/<[^>]*>/","",$str); } /** * Convert Object to array. * * @param unknown_type $objectValue * @return unknown */ function awp_convertObjToArray($objectValue) { if(!empty($objectValue)){ if(is_array($objectValue)) { $arrayValue = $objectValue; } else { $arrayValue = array(); array_push($arrayValue,$objectValue); } return $arrayValue; } }