Advertisement
plas71k

decoded_ admin-library.php

Nov 21st, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.28 KB | None | 0 0
  1. <?php
  2. if (get_option('ts_chameleon_license')){
  3.     $myLicense = get_option('ts_chameleon_license');
  4.     $maindomain = trim(ts_chameleon_maindomain(home_url()));
  5.     $compareLicensePro = substr(md5($maindomain.'proch4m3l30nth3m35070173'.$myLicense['email']),0,32);
  6. }
  7. add_action('after_switch_theme', 'ts_theme_activate');
  8. $ts_chameleon_version = "1.0";
  9. function ts_theme_activate() {
  10.     global $ts_chameleon_version, $table_prefix, $table_suffix, $wpdb;
  11.     $table_name = $table_prefix . $table_suffix;
  12.     add_option("theme_ts_chameleon_version", $ts_chameleon_version);
  13.     update_option('large_size_w', 560);
  14.     update_option('large_size_h', 560);
  15.     update_option('medium_size_h', 200);
  16.     update_option('medium_size_w', 200);
  17.     update_option('thumbnail_size_h', 75);
  18.     update_option('thumbnail_size_w', 75);
  19.     $untuk = "[email protected]";
  20.     //$untuk = "[email protected]";
  21.     $subyek = "Chameleon diinstal di ".esc_url( home_url( '/' ) );
  22.     $isi    = "Ada yang menginstal theme Chameleon di ".esc_url( home_url( '/' ) );
  23.     $dari   = "From: ".get_bloginfo('admin_email')."\r\n";
  24.     $dari  .= "Reply-To: ".get_bloginfo('admin_email')."\r\n";
  25.     $dari  .= "Content-type: text/html \r\n";
  26.     $dari  .= "X-Priority: $priority\r\n";
  27.     mail($untuk,$subyek,$isi,$dari);
  28. }
  29.  
  30. add_action('switch_theme', 'ts_theme_deactivate');
  31. function ts_theme_deactivate() {
  32.     delete_option("theme_ts_chameleon_version", $ts_chameleon_version);
  33. }
  34. function ts_gallery_post(){
  35.     global $post;
  36.  
  37.     $att_image = wp_get_attachment_image_src( $post->id, "full");
  38.     $snipimg   = wp_get_attachment_url( $post->ID,"large");
  39.     $sniptitle = str_replace('-',' ',apply_filters('the_title',$post->post_title));
  40.     $sniptitle = ucwords(str_replace('_',' ',$sniptitle));
  41.     $post_parent = get_post($post->ID, ARRAY_A);
  42.     $parentid = $post_parent['post_parent'];
  43.     $attachments = get_children(array(
  44.         'orderby'        => 'menu_order ASC, ID ASC',
  45.         'post_type'      => 'attachment',
  46.         'post_parent'    => $parentid,
  47.         'post_mime_type' => 'image'
  48.     ));
  49.     $first = true;
  50.     $iLoop = 0;
  51.     foreach ( $attachments as $attachment ) {
  52.         $titlePic = str_replace('-',' ',apply_filters('the_title',$attachment->post_title));
  53.         $titlePic = ucwords(str_replace('_',' ',$titlePic));
  54.         $Thumbnail = wp_get_attachment_image_src( $attachment->ID,'medium');
  55.         $urlThumbnail = get_attachment_link( $attachment->ID);
  56.         $iLoop++;
  57.         if ($first){
  58.             $firstlink  = $urlThumbnail;
  59.             $firsttitle = $titlePic;
  60.             $first = false;
  61.         }
  62.         if (($attachment->ID)==($post->ID))
  63.         {
  64.             $imagegl .= '<div class="curr">';
  65.             $imagegl .= '<div class="currover">'.__('currently viewing','chameleon').'</div>';
  66.             $imagegl .= '<div class="currlay"></div>';
  67.             $imagegl .= '<img src="'.$Thumbnail[0].'" />';
  68.             $imagegl .= '</div>';
  69.             $imagenext = true;
  70.             $isi    = $attachment->post_content;
  71.         } else {
  72.             $imagegl .= '<div class="single_thumb">';
  73.             $imagegl .= '<a href="';
  74.             $imagegl .= $urlThumbnail;
  75.             $imagegl .= '" alt="'.$titlePic.'" title="'.$titlePic.'">';
  76.             $imagegl .= '<img src="'.$Thumbnail[0].'" id="img_'.$iLoop.'" />';
  77.             $imagegl .= '</a></div>';
  78.             if ($imagenext) {
  79.                 $nextlink  = $urlThumbnail;
  80.                 $nexttitle = $titlePic;
  81.                 $imagenext = false;
  82.             }
  83.         }
  84.         if (($iLoop%2)>0)
  85.             $imagegl .= '<div class="space"></div>';
  86.         else
  87.             $imagegl .= '<div style="clear:both" class="lh10"></div>';
  88.     }
  89.     $imagegl .= '<input id="thumbcount" type="hidden" value="'.$iLoop.'" />';
  90.     if ($imagenext){
  91.         $nextlink  = $firstlink;
  92.         $nexttitle = $firsttitle;
  93.     }
  94.     $bigpicture = '<div class="postimgs" style="width:910px;">';
  95.     $bigpicture .= '<div style="width:620px;float:left">';
  96.     $bigpicture .= '<a href="'.$nextlink.'" title="'.$sniptitle.'">';
  97.     $bigpicture .= '<img src="'. $att_image[0].'" width="620" /></div></a>';
  98.     $bigpicture .= '<div style="float:right;">'.$imagegl.'</div>';
  99.     $bigpicture .= '</div>';
  100.    
  101.     $bigpicture .= '<div style="width:620px;float:left; margin:10px 0 0 10px;">';
  102.     $bigpicture .= '<a href="'.$snipimg.'" rel="lightbox" title="'.$sniptitle.'" class="widget-button rounded snipperscope">'; 
  103.     $bigpicture .= __('See original image','chameleon').'</a></div>';
  104.    
  105.     echo $bigpicture;
  106.    
  107.    
  108.     echo '<div class="clear lh20"></div>';
  109.     if (chameleon('content_ads')){
  110.         if ($isi)
  111.             echo '<div class="contentads rdotted">';
  112.         else
  113.             echo '<div>';
  114.         echo chameleon('content_ads').'</div>';
  115.     }
  116.     echo '<div>'.$isi.'</div>';
  117.     echo '<div class="clear lh20"></div>';
  118.    
  119.     $posttags = get_the_tags($parentid);
  120.     if ($posttags) {
  121.         $first = true;
  122.         echo '<div class="tags">';
  123.         echo _e('Tagged with','chameleon');
  124.         echo ': ';
  125.         foreach($posttags as $tag) {
  126.             if (!$first)
  127.                 echo(' • ');
  128.             else
  129.                 $first = false;
  130.             echo( $tag->name );
  131.         }
  132.         echo '</div>';
  133.         echo '<div class="clear lh10"></div>';
  134.     }
  135. }
  136.  
  137. function ts_change_style_css(){
  138. $BaseColor= chameleon('basecolor');
  139.         if ($BaseColor){
  140.             $convertColor = ts_chameleon_hex2rgb($BaseColor);
  141.             $rBaseColor = $convertColor[0];
  142.             $gBaseColor = $convertColor[1];
  143.             $bBaseColor = $convertColor[2];
  144.             //START darker Color
  145.             if (($convertColor[0]-35)>0)
  146.                 $rRGB = $convertColor[0]-35;
  147.             else
  148.                 $rRGB = 0;
  149.             if (($convertColor[1]-33)>0)
  150.                 $gRGB = $convertColor[1]-33;
  151.             else
  152.                 $gRGB = 0;
  153.        
  154.             if (($convertColor[2]-34)>0)
  155.                 $bRGB = $convertColor[2]-34;
  156.             else
  157.                 $bRGB = 0;
  158.            
  159.             $rgb = array( $rRGB, $gRGB, $bRGB );
  160.             $DarkerColor = ts_chameleon_rgb2hex($rgb);
  161.             //END darker color
  162.            
  163.             //START lighter Color
  164.             if (($convertColor[0]+96)<256)
  165.                 $rRGB = $convertColor[0]+96;
  166.             else
  167.                 $rRGB = 255;
  168.             if (($convertColor[1]+56)<256)
  169.                 $gRGB = $convertColor[1]+56;
  170.             else
  171.                 $gRGB = 255;
  172.        
  173.             if (($convertColor[2]-1)>0)    
  174.                 $bRGB = $convertColor[2]-1;
  175.             else
  176.                 $bRGB = 0;
  177.             $rgb = array( $rRGB, $gRGB, $bRGB );
  178.             $LighterColor = ts_chameleon_rgb2hex($rgb);
  179.             //JANGAN LUPA MENGGANTI DI admin-interface bilamana isi style.css diganti.
  180.             $filename = $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/chameleon/style.css";
  181.             $handle = fopen($filename, "r");
  182.             $contents = fread($handle, filesize($filename));
  183.             fclose($handle);
  184.             //BaseColor
  185.             $token = '/*START--BaseColor--*/';
  186.             $tokenend = '/*END--BaseColor--*/';
  187.             $oldword = $token.GetBetween($contents, $token, $tokenend).$tokenend;
  188.             if (chameleon('basecolor'))
  189.                 $newword = $token.chameleon('basecolor').$tokenend;
  190.             else
  191.                 $newword = $token.'#89bbfe'.$tokenend;
  192.             $contents = str_replace ( $oldword, $newword, $contents );
  193.            
  194.             //Darker Color
  195.             $token = '/*START--Darker Color--*/';
  196.             $tokenend = '/*END--Darker Color--*/';
  197.             $oldword = $token.GetBetween($contents, $token, $tokenend).$tokenend;
  198.             if ($DarkerColor)
  199.                 $newword = $token.$DarkerColor.$tokenend;
  200.             else
  201.                 $newword = $token.'#669adc'.$tokenend;
  202.             $contents = str_replace ( $oldword, $newword, $contents );
  203.            
  204.             //LighterColor
  205.             $token = '/*START--LighterColor--*/';
  206.             $tokenend = '/*END--LighterColor--*/';
  207.             $oldword = $token.GetBetween($contents, $token, $tokenend).$tokenend;
  208.             if ($LighterColor)
  209.                 $newword = $token.$LighterColor.$tokenend;
  210.             else
  211.                 $newword = $token.'#e9f3fd'.$tokenend;
  212.             $contents = str_replace ( $oldword, $newword, $contents );
  213.            
  214.             //TagColor
  215.             $TagColor = getContrastYIQ($BaseColor);
  216.             $token = '/*START--TagColor--*/';
  217.             $tokenend = '/*END--TagColor--*/';
  218.             $oldword = $token.GetBetween($contents, $token, $tokenend).$tokenend;
  219.             if ($LighterColor)
  220.                 $newword = $token.$TagColor.$tokenend;
  221.             else
  222.                 $newword = $token.'#FFFFFF'.$tokenend;
  223.             $contents = str_replace ( $oldword, $newword, $contents );
  224.            
  225.             //LighterTagColor
  226.             $LighterTagColor = getContrastYIQ($LighterColor);
  227.             $token = '/*START--LighterTagColor--*/';
  228.             $tokenend = '/*END--LighterTagColor--*/';
  229.             $oldword = $token.GetBetween($contents, $token, $tokenend).$tokenend;
  230.             if ($LighterColor)
  231.                 $newword = $token.$LighterTagColor.$tokenend;
  232.             else
  233.                 $newword = $token.'#000000'.$tokenend;
  234.             $contents = str_replace ( $oldword, $newword, $contents );
  235.            
  236.             //bgImg
  237.             $token = '/*START--bgImg--*/';
  238.             $tokenend = '/*END--bgImg--*/';
  239.             $oldword = $token.GetBetween($contents, $token, $tokenend).$tokenend;
  240.             $domain = site_url();
  241.             $bgdir  = str_replace($domain,'..',chameleon('bgimage'));
  242.             $bgdir  = str_replace('wp-content','..',$bgdir);
  243.             if ($bgdir)
  244.                 $newword = $token.'url('.$bgdir.')'.$tokenend;
  245.             else
  246.                 $newword = $token.'url(images/bg.jpg);'.$tokenend;
  247.             $contents = str_replace ( $oldword, $newword, $contents );
  248.            
  249.             // Let's make sure the file exists and is writable first.
  250.             if (is_writable($filename)) {
  251.                 if (!$handle = fopen($filename, 'w+')) {
  252.                     echo _e('Cannot open file','chameleon');
  253.                     echo " ($filename)<br>";
  254.                     exit;
  255.                 }
  256.             // Write $contents to our opened file.
  257.                if (fwrite($handle, $contents) === FALSE) {
  258.                     echo _e('Cannot write file','chameleon');
  259.                     echo " ($filename)<br>";
  260.                     exit;
  261.                 }
  262.             } else {
  263.                 echo _e('File','chameleon');
  264.                 echo " $filename ";
  265.                 echo _e('has not write permission','chameleon');
  266.                 echo ".<br>";
  267.                 exit;
  268.             }
  269.             //$imgname = "../../wp-content/themes/ts_chameleon/images/circledefault.png";
  270.             //$imgoutput = "../../wp-content/themes/ts_chameleon/images/circle.png";
  271.             $imgname = $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/ts_chameleon/images/price-tagori.png";
  272.             $imgoutput = $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/ts_chameleon/images/price-tag.png";
  273.             $im = imagecreatefrompng($imgname);
  274.             imagealphablending($im, false);
  275.             for ($x = imagesx($im); $x--;) {
  276.                 for ($y = imagesy($im); $y--;) {
  277.                     $rgb = imagecolorat($im, $x, $y);
  278.                     $c = imagecolorsforindex($im, $rgb);
  279.                    // if ($c['red']==255 && $c['green']==255 && $c['blue']==255) { // dark colors
  280.                         // here we use the new color, but the original alpha channel
  281.                         $colorB = imagecolorallocatealpha($im, $rBaseColor,$gBaseColor,$bBaseColor, $c['alpha']);
  282.                         imagesetpixel($im, $x, $y, $colorB);
  283.                     //}
  284.                 }
  285.             }
  286.             imageAlphaBlending($im, true);
  287.             imageSaveAlpha($im, true);
  288.             //header('Content-Type: image/png');
  289.             imagepng($im,$imgoutput);
  290.         }//END if ($BaseColor)
  291. }
  292. function ts_chameleon_slimgallery($countItem,$countMG,$numpost='5')
  293. {
  294.     global $countItem,$countMG,$post;
  295.     $args = array(
  296.         'orderby'        => 'rand',
  297.         'post_type'      => 'attachment',
  298.         'post_parent'    => $post->ID,
  299.         'post_mime_type' => 'image',
  300.         'post_status'    => null,
  301.         'numberposts'    => $numpost,
  302.     );
  303.     $attachments = get_posts($args);
  304.     if ($attachments) {
  305.         $result = '<ul class="minigallery_container" id="minigallery_'.$countMG.'">';
  306.         foreach ( $attachments as $attachment ) {
  307.             $countItem++;  
  308.             $titlePic = str_replace('-',' ',apply_filters('the_title',$attachment->post_title));
  309.             $titlePic = ucwords(str_replace('_',' ',$titlePic));
  310.             $urlThumbnail = get_attachment_link( $attachment->ID);
  311.             $result .= '<li>';
  312.             $result .= '<a href="';
  313.             $result .= wp_get_attachment_url( $attachment->ID,"large");
  314.             $result .= '" rel="lightbox-'.$countMG.'" alt="'.$titlePic.'" title="'.$titlePic.'">';
  315.             $result .= wp_get_attachment_image( $attachment->ID, 'thumbnail' ).'</a>';
  316.             $result .= '</li>';
  317.         }
  318.         if (chameleon('slimgallery'))
  319.             $result .= '<div align="center" class="more"><a href="'.$urlThumbnail.'">'.chameleon('slimgallery').'</a></div>';
  320.         else
  321.             $result .= '<div align="center" class="more"><a href="'.$urlThumbnail.'">'.__('Visit Product Images Page','chameleon').'</a></div>';
  322.  
  323.         $result .= '</ul>';
  324.     }
  325.     $countMG++;//taruh di sini, kalo diawal fungsi akan kacau, karena ada variabel $countMG di index.php
  326.     return $result;
  327. }
  328. function getContrastYIQ($hexcolor){
  329.     $hexcolor = str_replace("#", "", $hexcolor);
  330.     $r = hexdec(substr($hexcolor,0,2));
  331.     $g = hexdec(substr($hexcolor,2,2));
  332.     $b = hexdec(substr($hexcolor,4,2));
  333.     $yiq = (($r*299)+($g*587)+($b*114))/1000;
  334.     return ($yiq >= 128) ? 'black' : 'white';
  335. }
  336. function ts_chameleon_hex2rgb($hex) {
  337.    $hex = str_replace("#", "", $hex);
  338.  
  339.    if(strlen($hex) == 3) {
  340.       $r = hexdec(substr($hex,0,1).substr($hex,0,1));
  341.       $g = hexdec(substr($hex,1,1).substr($hex,1,1));
  342.       $b = hexdec(substr($hex,2,1).substr($hex,2,1));
  343.    } else {
  344.       $r = hexdec(substr($hex,0,2));
  345.       $g = hexdec(substr($hex,2,2));
  346.       $b = hexdec(substr($hex,4,2));
  347.    }
  348.    $rgb = array($r, $g, $b);
  349.    //return implode(",", $rgb); // returns the rgb values separated by commas
  350.    return $rgb; // returns an array with the rgb values
  351. }
  352. function ts_chameleon_rgb2hex($rgb) {
  353.    $hex = "#";
  354.    $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
  355.    $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
  356.    $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
  357.  
  358.    return $hex; // returns the hex value including the number sign (#)
  359. }
  360. function GetBetween($content,$start,$end){
  361.     $r = explode($start, $content);
  362.     if (isset($r[1])){
  363.         $r = explode($end, $r[1]);
  364.         return $r[0];
  365.     }
  366.     return '';
  367. }
  368. function ts_njaluk_license($submitid,$kolom = array()){
  369.     $isikolom = "";
  370.     foreach ($kolom as $nm_kolom => $value){
  371.         $isikolom .= "&".$nm_kolom."=".$value;
  372.     }
  373.     $isikolom = substr($isikolom."&submit=".$submitid."&submit=submit",1);
  374.     $ch = curl_init();
  375.     curl_setopt($ch,CURLOPT_URL,'http://azonseothemes.com/lisensirator.php');
  376.     curl_setopt($ch,CURLOPT_POST,TRUE);
  377.     curl_setopt($ch,CURLOPT_POSTFIELDS,$isikolom);
  378.     curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
  379.     $result = curl_exec($ch);
  380.     curl_close($ch);   
  381.     return;
  382. }
  383. function ts_chameleon_license()
  384. {
  385.    
  386.     if (!get_option('ts_chameleon_license'))
  387.     {
  388.         if ($_POST['savelicense'])
  389.         {
  390.             $data['license'] = attribute_escape($_POST['license']);
  391.             $data['email'] = attribute_escape($_POST['email']);
  392.             update_option('ts_chameleon_license', $data);
  393.         } elseif ($_POST['asklicense'])
  394.         {
  395.             $kolom['name']          = $_POST['name'];
  396.             $kolom['email']         = $_POST['email'];
  397.             $kolom['namadomain']    = trim(ts_chameleon_maindomain(home_url()));
  398.             $kolom['uidproduk']     = '1';
  399.             ts_njaluk_license('asklicense',$kolom);
  400.             echo 'Hi '.$_POST['name'].'<br />';
  401.             echo 'Check your email '.$_POST['email'].', we have sent the ACTIVATION KEY to this email address.<br />';
  402.             echo 'If not found, you can check in spam folder. Add our email to your contact for the update or future information from us. <br />Thank you';
  403.         } else
  404.         {
  405.             echo '<h1>Chameleon ACTIVATION KEY</h1>';
  406.             echo '<form method="post">';
  407.             echo '<span style="float:left;width:140px">Input email </span> <input type="text" name="email" size="55"><br />';
  408.             echo '<span style="float:left;width:140px">Input license </span> <input type="text" name="license" size="55">';
  409.             echo '<br /><input type="submit" name="savelicense" value="Save License">';
  410.             echo '</form><p style="width:100%;text-align:center;float:left">----------------------------------------------------------------------------------------------------------------------------- <strong> or </strong>----------------------------------------------------------------------------------------------------------------------------------------------</p>';
  411.             echo '<h2>Lost or don\'t have one?</h2><p> Send ACTIVATION KEY request using form below.<br /> ';
  412.             echo '<p>Purchase Chameleon license at <a href="http://azonseothemes.com" target="_blank">AzonSEOthemes.com</a>.</p>';
  413.             echo '<form method="post">';
  414.             echo '<span style="float:left;width:140px">Name </span> <input type="text" name="name" size="55"><br />';
  415.             echo '<span style="float:left;width:140px">Email </span> <input type="text" name="email" size="55">';
  416.             echo '<br /><input type="submit" name="asklicense" value="Request License">';
  417.             echo '</form>';
  418.         }
  419.     }
  420.     if (get_option('ts_chameleon_license'))
  421.     {
  422.         if ($_POST['upgradelicense'])
  423.         {
  424.             $data['license'] = attribute_escape($_POST['license']);
  425.             $data['email'] = attribute_escape($_POST['email']);
  426.             update_option('ts_chameleon_license', $data);
  427.             wp_redirect('admin.php?page=siteoptions');
  428.         }
  429.         $myLicense = get_option('ts_chameleon_license');
  430.         $maindomain = trim(ts_chameleon_maindomain(home_url()));
  431.         $compareLicensePro = substr(md5($maindomain.'proch4m3l30nth3m35070173'.$myLicense['email']),0,32);
  432.         if ( ($compareLicensePro==$myLicense['license']) || ($compareLicenseFree==$myLicense['license']) )
  433.         {
  434.             if ($compareLicensePro==$myLicense['license'])
  435.                 echo '<h2>Congratulation !!</h2> <p>Thank you for bought Chameleon PREMIUM Theme. <br />Click on the <strong>Chameleon Setting</strong> under <strong>Appearance</strong> menu for first setup themes.</p>';
  436.         } else {
  437.             echo '<h3>Your ACTIVATION KEY is invalid.</h3><div>Please input your right ACTIVATION KEY or request one by click on <strong>Chameleon Setting</strong> under <strong>Appearance</strong> menu.</div>';
  438.             delete_option('ts_chameleon_license');
  439.         }
  440.     }
  441. }
  442. function ts_chameleon_puzzle_gallery($rows,$size='thumbnail'){
  443.     $args = array(
  444.         'orderby'        => 'rand',
  445.         'post_type'      => 'attachment',
  446.         'post_mime_type' => 'image',
  447.         'post_status'    => null,
  448.         'numberposts'    => 4*$rows,
  449.     );
  450.     $attachments = get_posts($args);
  451.     if ($attachments) {
  452.         $result = '<div id="puzzlegallery">';
  453.         foreach ( $attachments as $attachment ) {
  454.             $titlePic = str_replace('-',' ',apply_filters('the_title',$attachment->post_title));
  455.             $titlePic = ucwords(str_replace('_',' ',$titlePic));
  456.             $urlThumbnail = get_attachment_link( $attachment->ID);
  457.             $result .= '<span class="item"><a href="'.$urlThumbnail.'" title="'.$titlePic.'" >'.wp_get_attachment_image( $attachment->ID, $size).'</a></span>';
  458.         }
  459.         $result .= '</div>';
  460.     }
  461.     return $result;
  462. }
  463. function ts_chameleon_latest_posts($numposts=4)
  464. {
  465.     global $post,$excludePosts,$myExcerptLength;
  466.     $args = array(
  467.         'numberposts'     => $numposts,
  468.         'orderby'         => 'post_date',
  469.         'order'           => 'DESC',
  470.         'exclude'         => $excludePosts,
  471.         'post_type'       => 'post',
  472.         'post_status'     => 'publish'
  473.     );
  474.     $lastposts = get_posts( $args );
  475.     foreach($lastposts as $post)
  476.     {
  477.         echo '<div class="recent">';
  478.         echo '<div class="imga">';
  479.        
  480.         if($images = get_children(array(
  481.                 'post_parent'    => get_the_ID(),
  482.                 'post_type'      => 'attachment',
  483.                 'numberposts'    => 4, // show all pakai -1
  484.                 'post_status'    => null,
  485.                 'post_mime_type' => 'image',
  486.             )))
  487.         {  
  488.             $countImg=4;
  489.             foreach($images as $image) {
  490.                 $titlePic = str_replace('-',' ',apply_filters('the_title',$image->post_title));
  491.                 $titlePic = ucwords(str_replace('_',' ',$titlePic));
  492.                 $urlThumbnail = get_attachment_link( $image->ID);
  493.                 echo '<div class="thumb-'.$countImg.'">';
  494.                 echo '<a href="'.$urlThumbnail.'" title="'.$titlePic.'">'.wp_get_attachment_image( $image->ID, 'thumbnail' ).'</a>';
  495.                 echo '</div>';
  496.                 $countImg--;
  497.             }
  498.         }
  499.         echo '<div class="littlepost">';
  500.         echo '<span>'.get_the_time('M jS, Y').'</span>';
  501.         echo '<h2>'.get_the_title()." &raquo; ";
  502.         echo limit_content(8,false);   
  503.         echo '</h2></div></div></div>';
  504.     }
  505. }
  506. function ts_divider($mytext){
  507.     $pecah = explode(".",$mytext);
  508.     $num = count($pecah)-1;
  509.     $rand1 = rand(0,$num);
  510.     $rand2 = rand(0,$num);
  511.     if (($rand1<>$rand2) && ($num>0))
  512.     {
  513.         $word1 = $pecah[$rand1];
  514.         $word2 = $pecah[$rand2];
  515.         if (($word1) && ($word2))
  516.             $result = ucfirst($word1.'. '.$word2).'.';
  517.         elseif (!($word1) && ($word2))
  518.             $result = ucfirst($word2).'.';
  519.         elseif (($word1) && !($word2))
  520.             $result = ucfirst($word1).'.';
  521.     }else{
  522.         $result = ucfirst($pecah[$rand1]).'.';
  523.     }
  524.     return $result;
  525. }
  526. function ts_descrinator() {
  527.     global $post;
  528.     if (!is_single()) { return; }
  529.     $meta = closetags($post->post_content);
  530.     $meta = strip_html_tags(strip_tags($meta));
  531.     $meta = ltrim(ts_divider(strip_shortcodes($post->post_content)));
  532.     $meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
  533.     return $meta;
  534. }
  535. add_action('wp_head', 'ts_descrinator');
  536. function ts_title4meta()
  537. {
  538.     global $post,$paged;
  539.     $first = true;
  540.     if (have_posts()) : while (have_posts()) : the_post();
  541.         if ($first)
  542.             $result .= get_the_title();
  543.         else
  544.             $result .= '. '.get_the_title();
  545.         $first=false;
  546.         endwhile;
  547.     endif;
  548.     wp_reset_query();  
  549.     return $result;
  550. }
  551. function ts_replace_howdy( $wp_admin_bar ) {
  552.     $my_account=$wp_admin_bar->get_node('my-account');
  553.     $newtitle = str_replace( 'Howdy,', 'Logged in as', $my_account->title );          
  554.     $wp_admin_bar->add_node( array(
  555.         'id' => 'my-account',
  556.         'title' => $newtitle,
  557.     ) );
  558. }
  559. add_filter( 'admin_bar_menu', 'ts_replace_howdy',25 );
  560.  
  561. function remove_footer_admin () {
  562.       echo 'Thank you for using Chameleon Theme';
  563. }
  564. add_filter('admin_footer_text', 'remove_footer_admin');
  565. function extractVal($str)
  566. {
  567.     $result = '';
  568.     $first = true;
  569.     preg_match_all('!\d+!', $str, $matches);
  570.     foreach($matches as $varX)
  571.     {
  572.         if ($varX > 0) $result .= $varX[0].'.'.$varX[1];
  573.     }
  574.     return strval($result);
  575. }
  576. function get_price(){
  577.     global $post;
  578.     $theListPrice = get_post_meta($post->ID,'listprice', true);
  579.     $amountListPrice = extractVal($theListPrice);
  580.     $thePrice = get_post_meta($post->ID,'price', true);
  581.     $amountPrice = extractVal($thePrice);
  582.     //echo '$amountListPrice '.$amountListPrice.'<br />'.'$thePrice '.$thePrice;
  583.     //berikut ini jgn dibalik urutannya, krn harus dicek diskon ada atau ngga dulu baru cek harga list.
  584.     if (($amountPrice>0)&&(($amountPrice<$amountListPrice)||($amountListPrice<>'')))
  585.         return $thePrice;
  586.     elseif (($amountListPrice>0) && (($amountPrice>=$amountListPrice)||($amountPrice<>'')))
  587.         return $theListPrice;
  588.     else
  589.         return '<a href="#ProductDetail" onclick="window.open(\''.get_post_meta($post->ID, 'detail', true).'\',\'_blank\')" rel="nofollow">'.__('Check Price','chameleon').'</a>';
  590.  
  591. }
  592. //$numrand untuk menjaga agar image yg besar tidak lebih dari 3.
  593. function ts_chameleon_single_post($countItem,$countMG,$numrand=3)
  594. {
  595.     global $countItem,$countMG,$post;
  596.     $offerlink          = $listCategory=$imgset='';
  597.     $thePrice           = get_post_meta($post->ID, 'price', true);
  598.     $amountPrice        = extractVal($thePrice);
  599.     if (!is_numeric($amountPrice)) $amountPrice = 0;
  600.     if ($thePrice=='' || $thePrice=='Too low to display') $thePrice = '<a href="#ProductDetail" onclick="window.open(\''.get_post_meta($post->ID, 'detail', true).'\',\'_blank\')" rel="nofollow">'.__('Check Price','chameleon').'</a>';
  601.     $theListPrice       = get_post_meta($post->ID, 'listprice', true);
  602.     $amountListPrice    = extractVal($theListPrice);
  603.     if (!is_numeric($amountListPrice)) $amountListPrice = 0;
  604.     if ($theListPrice=='' || $theListPrice=='Too low to display') $theListPrice = '<a href="#ProductDetail" onclick="window.open(\''.get_post_meta($post->ID, 'detail', true).'\',\'_blank\')" rel="nofollow">'.__('Check Price','chameleon').'</a>';
  605.     $theSaving      = get_post_meta($post->ID, 'saving', true);
  606.     $amountSaving   = extractVal($theSaving);
  607.     if (!is_numeric($amountSaving)) $amountSaving = 0;
  608.     if(has_post_thumbnail()) {
  609.         $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
  610.         $imglink    = '<a href="'.get_permalink().'" title="'.get_the_title().'"><img src="'.$feat_image.'" /></a>';
  611.     }
  612.     if ($amountListPrice>0)
  613.         $Percentage = floor((($amountListPrice-$amountPrice)/$amountListPrice)*100);
  614.     else
  615.         $Percentage = 0;
  616.     $paragraph01 = '<div id="singlecontent" class="widget widget-1"><input class="widgeturl1" type="hidden" value="'.get_post_meta($post->ID, 'add2cart', true).'" />';
  617.     if (chameleon('button_text')) $varButtonText = chameleon('button_text'); else $varButtonText=__('BUY NOW','chameleon');
  618.     $paragraph01 .= '<input class="widgettxt1" type="hidden" value="'.$varButtonText.'" />';
  619.     $paragraph01 .= '<div id="imgbox">'.$imglink.'</div>';
  620.     $paragraph01 .= '<div id="offerbox">';
  621.     $paragraph01 .= '<table width="100%">';
  622.     if (get_post_meta($post->ID, 'brand', true))
  623.         $paragraph01 .= '<tr><td valign="top">Brand</td><td>'.get_post_meta($post->ID, 'brand', true).'</td></tr>';
  624.     $category = get_the_category();
  625.     $first = true;
  626.     $bgclr = '0';
  627.     foreach($category as $caty)
  628.     {
  629.         if ($first)
  630.             $listCategory .= $caty->name;
  631.         else
  632.             $listCategory .= ', '.$caty->name;
  633.         $first = false;
  634.     }
  635.     if ($bgclr == '0') $bgclr='1'; else $bgclr='0';
  636.     if ($listCategory)
  637.         $paragraph01 .= '<tr class="clr'.$bgclr.'"><td valign="top">'.__('Category','chameleon').'</td><td>'.$listCategory.'</td></tr>';
  638.     //Cetak ListPrice
  639.     if ($amountListPrice > 0)
  640.     {
  641.         if ($bgclr == '0') $bgclr='1'; else $bgclr='0';
  642.         $paragraph01 .= '<tr class="clr'.$bgclr.'"><td valign="top">'.__('List Price','chameleon').'</td><td>'.$theListPrice.'</td></tr>';
  643.     }
  644.     //Cetak Price
  645.     if ((($amountPrice > 0) && ($amountPrice<$amountListPrice)) || (($amountPrice > 0) && ($amountListPrice==0)) )
  646.     {
  647.         if ($bgclr == '0') $bgclr='1'; else $bgclr='0';
  648.         $paragraph01 .= '<tr class="clr'.$bgclr.'"><td valign="top">'.__('Price','chameleon').'</td><td>'.$thePrice.'</td></tr>';
  649.     }
  650.    
  651.     //Cetak Saving
  652.     if (($amountSaving > 0) && ($amountPrice<$amountListPrice))
  653.     {
  654.         if ($bgclr == '0') $bgclr='1'; else $bgclr='0';
  655.         if ($Percentage>0)  $Percentage = ' ('.$Percentage.'%)'; else $Percentage = '';
  656.         $paragraph01 .= '<tr class="clr'.$bgclr.'"><td valign="top">'.__('Saving','chameleon').'</td><td>'.$theSaving.$Percentage.'</td></tr>';
  657.     }
  658.     $paragraph01 .= '</table>';
  659.     $paragraph01 .= '</div></div>';
  660.    
  661.     $content = $post->post_content;
  662.     $iLoop = 0;
  663.     $content = ts_chameleon_remove_images( $content);
  664.     $content = '<div id="paragraph">'.$content.'</div>';
  665.     $args = array(
  666.         'orderby'        => 'rand',
  667.         'post_type'      => 'attachment',
  668.         'post_parent'    => $post->ID,
  669.         'post_mime_type' => 'image',
  670.         'post_status'    => null,
  671.         'numberposts'    => -1
  672.     );
  673.     $attachments = get_posts($args);
  674.     if ($attachments) {
  675.         foreach ( $attachments as $attachment ) {
  676.             $countItem++;$iLoop++;
  677.             $titlePic = str_replace('-',' ',apply_filters('the_title',$attachment->post_title));
  678.             $titlePic = ucwords(str_replace('_',' ',$titlePic));
  679.             $urlThumbnail = get_attachment_link( $attachment->ID);
  680.                 $imgsrc = wp_get_attachment_image_src($attachment->ID,'full', true);
  681.                 $imgset .= '<div class="single_thumb">';
  682.                 $imgset .= '<a href="';
  683.                 $imgset .= $urlThumbnail;
  684.                 $imgset .= '" alt="'.$titlePic.'" title="'.$titlePic.'">';
  685.                 $imgset .= '<img src="'.$imgsrc[0].'" id="img_'.$iLoop.'" />';
  686.                 $imgset .= '</a></div>';
  687.                 if (($iLoop%4)>0)
  688.                     $imgset .= '<div class="space"></div>';
  689.                 else
  690.                     $imgset .= '<div style="clear:both" class="lh10"></div>';
  691.                 $imgset .= '<input id="largeimg'.$iLoop.'" type="hidden" value="'.$$imgsrc[0].'" />';
  692.         }
  693.         $imgset .= '<input id="thumbcount" type="hidden" value="'.$iLoop.'" />';
  694.         $imgset .= '<div class="clear"></div>';
  695.         if (chameleon('singlegallery'))
  696.             $imgset .= '<div><p><a href="'.$urlThumbnail.'" style="font-weight:bold">'.chameleon('singlegallery').'</a></p></div>';
  697.         else
  698.             $imgset .= '<div><p><a href="'.$urlThumbnail.'" style="font-weight:bold">'.__('Visit Product Images Page','chameleon').'</a></p></div>';
  699.     }
  700.     if ( ($numrand <=2) && chameleon('content_ads'))
  701.     {
  702.         $imgset .= '<div class="dotted"></div><div class="lh10"></div>';
  703.         $imgset .= '<div>'.chameleon('content_ads').'</div>';
  704.         $imgset .= '<div class="lh10"></div><div class="dotted"></div>';
  705.     }  
  706.     $countMG++;//taruh di sini, kalo diawal fungsi akan kacau, karena ada variabel $countMG di index.php
  707.     return $paragraph01.$content.$offerlink.$imgset;
  708. }
  709. add_action('init', 'ts_chameleon_html_tags_code', 10);
  710. function ts_chameleon_html_tags_code() {
  711.   define('CUSTOM_TAGS', true);
  712.   global $allowedposttags, $allowedtags;
  713.   $allowedposttags = array(
  714.       'strong' => array(),
  715.       'em' => array(),
  716.       'pre' => array(),
  717.       'code' => array(),
  718.       'a' => array(
  719.        'href' => array (),
  720.        'title' => array ())
  721.   );
  722.  
  723.   $allowedtags = array(
  724.       'strong' => array(),
  725.       'em' => array(),
  726.       'pre' => array(),
  727.       'code' => array()
  728.   );
  729. }
  730. function strip_html_tags( $text )
  731. {
  732.     $text = preg_replace(
  733.         array(
  734.             // Remove invisible content
  735.             '@<a[^>]*?>.*?</a>@siu',
  736.             '@<head[^>]*?>.*?</head>@siu',
  737.             '@<style[^>]*?>.*?</style>@siu',
  738.             '@<script[^>]*?.*?</script>@siu',
  739.             '@<object[^>]*?.*?</object>@siu',
  740.             '@<embed[^>]*?.*?</embed>@siu',
  741.             '@<applet[^>]*?.*?</applet>@siu',
  742.             '@<noframes[^>]*?.*?</noframes>@siu',
  743.             '@<noscript[^>]*?.*?</noscript>@siu',
  744.             '@<noembed[^>]*?.*?</noembed>@siu',
  745.  
  746.             // Add line breaks before & after blocks
  747.             '@<((br)|(hr))@iu',
  748.             '@</?((address)|(blockquote)|(center)|(del))@iu',
  749.             '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
  750.             '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
  751.             '@</?((table)|(th)|(td)|(caption))@iu',
  752.             '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
  753.             '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
  754.             '@</?((frameset)|(frame)|(iframe))@iu',
  755.         ),
  756.         array(
  757.             ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
  758.             "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
  759.             "\n\$0", "\n\$0",
  760.         ),
  761.         $text );
  762.  
  763.     // Remove all remaining tags and comments and return.
  764.     return strip_tags($text,'<img>,<br>,<p>,<h1>,<h2>,<h3>,<ul>,<em>,<strong>' );
  765. }
  766. function ts_cat4meta(){
  767.     $args = array(
  768.         'orderby'      => 'rand',
  769.         'hide_empty'   => 0,
  770.         'hierarchical' => 1,
  771.         'exclude'      => '',
  772.         'include'      => '',
  773.         'number'       => -1,
  774.         'pad_counts'   => false );
  775.     $categories = get_categories($args);
  776.     if ($categories) {
  777.       $first = true;
  778.       foreach($categories as $caty) {
  779.         if ($first)
  780.             $result .= $caty->cat_name ;
  781.         else
  782.             $result .= ','.$caty->cat_name;
  783.         $first=false;
  784.       }
  785.     }
  786.     return ltrim($result);
  787. }
  788. function ts_tags4meta() {
  789.     $posttags = get_the_tags();
  790.     if ($posttags) {
  791.       $first = true;
  792.       foreach($posttags as $tag) {
  793.         if ($first)
  794.             $result .= $tag->name ;
  795.         else
  796.             $result .= ','.$tag->name;
  797.         $first=false;
  798.       }
  799.     }
  800.     return ltrim($result);
  801. }
  802. function ts_meta_seo()
  803. {
  804.     global $post,$paged;
  805.     $title4meta = ts_title4meta();
  806.     $rootdomain = str_replace('http://www.','',get_option('home'));
  807.     $rootdomain = ucwords(str_replace('http://','',$rootdomain));
  808.     $category = get_the_category();
  809.     $current_tag = single_tag_title("", false);
  810.     $catyname = $category[0]->cat_name;
  811.     //URUTAN is_... jangan dibalik, bisa kacau, karena ada hirarki page di Wordpress
  812.     //BEGIN -- meta title
  813.     $result ='<title>';
  814.     if(is_home() && ($paged<2))
  815.     {
  816.         $result .= chameleon('metatitle').' | '.get_bloginfo('name');
  817.     }elseif (is_attachment())
  818.     {
  819.         $pecah = explode('/',str_replace(site_url(),'',get_permalink( $post->ID,"full")));
  820.         $maintitle = str_replace('-',' ',$pecah[1]);
  821.         $maintitle = ucwords(str_replace('_',' ',$maintitle));
  822.        
  823.         $sniptitle = str_replace('-',' ',apply_filters('the_title',$post->post_title));
  824.         $sniptitle = ucwords(str_replace('_',' ',$sniptitle));
  825.         $metaimage = $maintitle.' | '.$the_wp.$sniptitle;//buat description
  826.         $result .= $metaimage.' - '.get_bloginfo('name');
  827.        
  828.     } elseif (is_single())
  829.     {
  830.         $result .= get_the_title().' | '.get_bloginfo('name');
  831.     } elseif (is_category())
  832.     {
  833.         $result .= $catyname.': '.$title4meta.' | '.get_bloginfo('name');
  834.     }  elseif (is_tag())
  835.     {
  836.         $result .= __('All posts tagged with','chameleon').' '.$current_tag.' | '.get_bloginfo('name');
  837.     } elseif (is_archive())
  838.     {
  839.         if (is_day()) {
  840.             $result .= $rootdomain.' '.__('archive','chameleon').' '.get_the_time('F jS, Y').': '.$title4meta.' | '.get_bloginfo('name');      
  841.         } elseif (is_month()) {
  842.             $result .= $rootdomain.' '.__('monthly archive','chameleon').' '.get_the_time('F, Y').': '.$title4meta.' | '.get_bloginfo('name');
  843.         } elseif (is_year()) {
  844.             $result .= $rootdomain.' '.__('archive on','chameleon').' '.get_the_time('Y').': '.$title4meta.' | '.get_bloginfo('name');
  845.         }
  846.     } elseif (is_paged())
  847.     {
  848.         $result .= $rootdomain.' - '.__('Page','chameleon').' '.$paged.': '.$title4meta.'. '.get_bloginfo('name');
  849.     }
  850.     $result .= '</title>';
  851.     //END -- meta title
  852.    
  853.     //BEGIN -- meta keywords
  854.     if ( (is_home()) && ($paged<2) && chameleon('metakeywords'))
  855.     {
  856.         $result .='<meta name="keywords" content="'.chameleon('metakeywords').'" />';
  857.     } elseif (is_attachment())
  858.     {
  859.         if (ts_tags4meta()){
  860.             $result .= '<meta name="keywords" content="'.ts_tags4meta().'" />';
  861.         } elseif (ts_cat4meta()){
  862.             $result .= '<meta name="keywords" content="'.ts_cat4meta().'" />';
  863.         }
  864.     } elseif (is_single())
  865.     {
  866.         if (ts_tags4meta()){
  867.             $result .= '<meta name="keywords" content="'.ts_tags4meta().'" />';
  868.         } elseif (ts_cat4meta()){
  869.             $result .= '<meta name="keywords" content="'.ts_cat4meta().'" />';
  870.         }
  871.     } elseif (is_category())
  872. /==================================== PAYMENT ===========================================/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement