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; } //Label Field function awp_labelfield($field,$class='contactform_field_label',$before='',$after='') { $fieldid=$field['fieldid']; $showtext=$field['showtext']; return $before.''.$after; } function awp_jobsearch_textfield ($field,$class='',$before='',$after='') { $fieldid = $field['fieldid']; $showtext = $field['showtext']; $required = $field['required']; $fieldtype = $field['type']; $options = $field['options']; switch( $fieldid ) { case "keywords" : $html = ''; break; case "customfield1" : if($fieldtype == 'select') : $html .= ''; endif; break; case "customfield2" : if($fieldtype == 'checkbox') : foreach($options as $opt_val) { $opt_value = strtoupper(trim($opt_val)); $opt_value = str_replace(" ","_",$opt_value); $html .= '   
'; } endif; if($fieldtype == 'select') : $html .= ''; endif; break; } return $html; } /** * Enter description here... * * @param unknown_type $forms * @param unknown_type $field * @param unknown_type $countries * @param Bollean $value_present * @param unknown_type $before * @param unknown_type $after * @return unknown */ function awp_textfield($forms='',$field='',$countries='',$value_present='',$before='',$after='') { $fieldid=$field['fieldid']; $showtext=$field['showtext']; $validation=$field['validation']; $required=$field['required']; $fieldtype=$field['type']; $options=$field['options']; $optionvalues=array(); if($fieldtype=="select" || $fieldtype=="radio" || $fieldtype=="checkbox" ){ if(trim($fieldid) == 'industry') { $optionvalues=$options; $fieldtype = 'select'; } else if(trim($options)!=""){ $optionvalues=split("[\n]",trim($options));//Split the String line by line. } } if ($value_present) : $postValue = $_REQUEST[$fieldid]; else : $postValue=""; endif; //Required Class if($required){ $mandate_property='"mandatory="true"'; $validateclass=" required"; } else{ $mandate_property=""; $validateclass=""; } //Field Validation Class switch($validation) { case "email": $validateclass .=" email"; break; case "url": $validateclass .=" url"; break; case "number": $validateclass .=" number"; break; } //Captcha Class if($fieldid=='captcha') { $captcha_class = 'captcha'; } else{ $captcha_class = ''; } switch($fieldtype) { case "text": $html = ''; break; case "textarea": $html = ''; break; case "select": if($fieldid == 'country'){ $html = ''; } else if($fieldid == 'industry') { if(!empty($optionvalues)) { $html .= ''; }else { $html .= ''; } } else{ $html = ''; } break; case "radio": $i=0; foreach( $optionvalues as $optionvalue ) { if(trim($postValue) == trim($optionvalue)){ $selected='checked="checked"'; } else{ $selected = ""; } if(!empty($optionvalue) && strlen(trim($optionvalue)) != 0) { if($i>0) $html .=' '; $html .=''; } } break; case "checkbox": $i=0; foreach( $optionvalues as $optionvalue ) { $selected =""; foreach($postValue as $value){ if(trim($value) == trim($optionvalue)){ $selected='checked="checked"'; } } if(!empty($optionvalue) && strlen(trim($optionvalue)) != 0) { if($i>0) $html .=' '; $html.=''; $i++; } } break; case "captcha": $html ='
'; break; case "file": $html =''; $html.= ''; break; } return $before.$html.$after; } /** * SubMit Button Type * * @param array $contactform * @return html field(form submit type) */ function awp_submit_type($forms='',$form_submitname='',$class='',$before='',$after='') { if(strlen(trim($form_submitname)) != 0 ) : $html =''; endif; if($forms[submit_button_type] == "submit" ){ if(strlen(trim($forms[submit_button_val])) != 0) { $value = $forms[submit_button_val]; }else { $value = 'Submit'; } $button_value = 'value="'.$value.'"'; } else{ if(strlen(trim($forms[submit_button_val])) == 0) { $imgSrc = awp_image('submit_button'); }else { $imgSrc = $forms[submit_button_val]; } $button_value = 'src="'.$imgSrc.'"'; } $html .= ''; return $before.$html.$after; } /** * Create Label Fields * * @param unknown_type $showtext * @param unknown_type $customtext * @param unknown_type $class * @param unknown_type $before * @param unknown_type $after * @return unknown */ function awp_create_labelfield($showtext,$customtext='',$class='',$before='',$after='',$fieldid='') { if($showtext == '' || strlen(trim($showtext)) == 0) : $showtext = $customtext; endif; return $before.''.$after; } function awp_create_textfiled($type,$fieldid,$class='',$before='',$after='') { switch(strtolower($type)) { case "checkbox" : $html = $before.''.$after; break; } return $html; } //Mandatory Field. function awp_mandatoryfield($field,$before='',$after='',$mandatory_symbol = '*') { $required=$field['required']; if($required): return $before.$mandatory_symbol.$after; else : return 0; endif; } //Powered By Apptivo. function poweredby_apptivo() { $apptivo_logo = ' Apptivo.com is the best free way to run your business. Apptivo.com powers ecommerce websites, provides free CMS, free CRM, free ERP, free Project Management and free Invoicing to small businesses. '; return $apptivo_logo; }