/**
 * Description :
 * Show the mixes 
 */
function showMix($url)
{
    // create a temporary directory for storing mix covers
    if (!file_exists(DIR_COVERS)) {
        mkdir(DIR_COVERS, 0777, true);
    }
    deleteAllFiles();
    $wf = new Workflows();
    $options = unserialize(OPTIONS);
    $json = $wf->request($url, $options);
    $data = json_decode($json, true);
    $mixes = $data['mix_set']['mixes'];
    $count = 1;
    foreach ($mixes as $mix) {
        // get mix info
        $mix_id = $mix['id'];
        $mix_name = $mix['name'];
        $url = "http://8tracks.com" . $mix['path'];
        $plays_count = $mix['plays_count'];
        $likes_count = $mix['likes_count'];
        $tracks_count = $mix['tracks_count'];
        $duration = $mix['duration'];
        $cover_url = $mix['cover_urls']['sq56'];
        // get mix cover from url
        $image_data = file_get_contents($cover_url);
        $image_name = $mix_id . '.png';
        file_put_contents(DIR_COVERS . '/' . $image_name, $image_data);
        // put image into temporary directory
        $wf->result('alfred8tracksworkflow.' . $count . '.' . time(), $url, trim($mix_name), '[' . number_format($plays_count) . ' plays] ' . '[' . number_format($likes_count) . ' likes] ' . '[' . $tracks_count . ' tracks] (' . gmdate("H:i:s", $duration) . ')', DIR_COVERS . '/' . $image_name);
        $count++;
    }
    return $wf->toxml();
}
                }
            } else {
                if (fileSizeDenied($file_size, $maxFileSize)) {
                    if (deleteAllFiles('datafile', $qtdeIntegrantes)) {
                        header("Location: http://tvcultura.cmais.com.br/preestreia/conjunto-2013?error=3");
                        die;
                    }
                } else {
                    if (sendMailAtt($to, $from, $subject, $message, $attach)) {
                        if (deleteAllFiles('datafile', $qtdeIntegrantes)) {
                            header("Location: http://tvcultura.cmais.com.br/preestreia/conjunto-2013?success=1");
                            die;
                        }
                    } else {
                        if (deleteAllFiles('datafile', $qtdeIntegrantes)) {
                            header("Location: http://tvcultura.cmais.com.br/preestreia/conjunto-2013?error=1");
                            die;
                        }
                    }
                }
            }
        } else {
            if (deleteAllFiles('datafile', $qtdeIntegrantes)) {
                header("Location: http://tvcultura.cmais.com.br/preestreia/conjunto-2013?error=4");
                die;
            }
        }
    }
}
?>
                
 function deleteAllFiles($directory = "")
 {
     if ($directory != "") {
         foreach (glob("{$directory}/*") as $file) {
             if (is_dir($file)) {
                 deleteAllFiles($file);
             } else {
                 unlink($file);
             }
         }
     }
 }
示例#4
0
/**
 * Parse and Import all link to WordPress
 * @param  integer $parser     Content parser used, 0 for using Readability API, 1 for using Fivefilters API.
 * @param  string  $url        URL list that will be parsed and imported to WordPress
 * @param  array   $categories Category for the imported articles.
 * @param  array   $tags       Tags for the imported articles.
 * @return Void              
 */
function importToWordPress($parser = 0, $url, $categories = array(), $tags = array())
{
    $objXMLRPClientWordPress = new XMLRPClientWordPress(WP_URL, WP_USERNAME, WP_PASSWORD);
    if (!is_null($url) || !empty($url)) {
        for ($i = 0; $i < count($url); $i++) {
            $startItem = $i + 1;
            $totalItem = count($url);
            $progressPecentage = $startItem * 100 / $totalItem;
            try {
                if ($parser == 0) {
                    // USE Readability as Parser
                    $content = file_get_contents(READABILITY_URL . '?url=' . $url[$i] . '&token=' . READABILITY_TOKEN);
                } else {
                    // USE Fivefilters as Parser
                    $content = file_get_contents(FIVEFILTERS_URL . '?url=' . $url[$i] . '&links=preserve&format=json');
                }
                // Check for any error on HTTP request
                if ($content === false) {
                    $allowedExts = array("jpg", "jpeg", "png", "gif");
                    $temp = explode(".", $url[$i]);
                    // Separate file name and it's extension
                    $file_ext = strtolower(end($temp));
                    //If the error url is image, add new post as images (For Readability API).
                    if (in_array($file_ext, $allowedExts) === true) {
                        echo "Image found, added as image to WordPress";
                        $objXMLRPClientWordPress->new_post('Image', '<figure><img src="' . $url[$i] . '" alt="image" /></figure>', array('images'), $tags[$i], array(array("key" => "source_url", "value" => $url[$i])));
                    }
                }
                $json = json_decode($content, true);
                if ($parser == 0) {
                    $article_title = $json['title'];
                    $article_content = $json['content'];
                } else {
                    $article_title = $json['rss']['channel']['item']['title'];
                    $article_content = $json['rss']['channel']['item']['description'];
                }
                // Print progress of succesfully title posted to WP
                echo htmlallentities($article_title) . " &raquo; Added<br>";
                // Post to WP
                $objXMLRPClientWordPress->new_post($article_title, $article_content, $categories, $tags[$i], array(array("key" => "source_url", "value" => $url[$i])));
                showProgressbar($progressPecentage);
            } catch (Exception $ex) {
                echo 'Caught exception: ', $e->getMessage(), "\n";
            }
        }
        deleteAllFiles('uploads');
        //Delete all Pocket HTML file insied uploads
        echo "<br/>Import Complete<br/>";
    }
}