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 */ /** * 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; } } /** * * @param $wsdl * @param string $publishdate_key * @param string $plugincall_key * @param $publishdate_function * @param $plugincall_function * @param $publishdate_params * @param $plugincall_params * @return */ function get_data($wsdl,$publishdate_key,$plugincall_key,$publishdate_function,$plugincall_function,$publishdate_params,$plugincall_params) { $cache_obj = new AWP_Cache_Util(); //Create Object in AWP_DataCache class $response = $cache_obj->get_data($wsdl, $publishdate_key, $plugincall_key, $publishdate_function, $plugincall_function, $publishdate_params, $plugincall_params); return $response; } /** * Recursive creates directory * * @param string $path * @param integer $mask * @param string * @return boolean */ function awp_mkdir($path, $mask = 0755, $curr_path = '') { $path = awp_realpath($path); $path = trim($path, '/'); $dirs = explode('/', $path); foreach ($dirs as $dir) { if ($dir == '') { return false; } $curr_path .= ($curr_path == '' ? '' : '/') . $dir; if (!@is_dir($curr_path)) { if (@mkdir($curr_path, $mask)) { @chmod($curr_path, $mask); } else { return false; } } } return true; } /** * Recursive remove dir * * @param string $path * @param array $exclude * @return void */ function awp_rmdir($path, $exclude = array(), $remove = true) { $dir = @opendir($path); if ($dir) { while (($entry = @readdir($dir)) !== false) { $full_path = $path . '/' . $entry; if ($entry != '.' && $entry != '..' && !in_array($full_path, $exclude)) { if (@is_dir($full_path)) { awp_rmdir($full_path, $exclude); } else { @unlink($full_path); } } } @closedir($dir); if ($remove) { @rmdir($path); } } } /** * Recursive empty dir * * @param string $path * @param array $exclude * @return void */ function awp_emptydir($path, $exclude = array()) { awp_rmdir($path, $exclude, false); } /** * Returns realpath of given path * * @param string $path */ function awp_realpath($path) { $path = awp_path($path); $parts = explode('/', $path); $absolutes = array(); foreach ($parts as $part) { if ('.' == $part) { continue; } if ('..' == $part) { array_pop($absolutes); } else { $absolutes[] = $part; } } return implode('/', $absolutes); } /** * Converts win path to unix * * @param string $path * @return string */ function awp_path($path) { $path = preg_replace('~[/\\\]+~', '/', $path); $path = rtrim($path, '/'); return $path; }