Subversion Repositories instagram

[/] [cronjobs/] [setDefaultTags.php] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ffruehstueck
<?php
2
 
3
$cli->output( 'Instagram set default tags STARTED');
4
 
5
$IGIni = eZINI::instance( 'instagram.ini' );
6
 
7
$importUserID =  $IGIni->variable( 'ImportSettings', 'ImportUserID' );
8
 
9
$user = eZUser::fetch( $importUserID );
10
 
11
$db = eZDB::instance();
12
 
13
eZIGFunctionCollection::fetchAllImages( );
14
 
15
$allImageArray = eZIGPhotos::fetchAll();
16
 
17
$config = array(
18
    'client_id' => $IGIni->variable( 'instagram', 'ClientId' ),
19
    'client_secret' => $IGIni->variable( 'instagram', 'ClientSecret' ),
20
    'grant_type' => 'authorization_code',
21
    'redirect_uri' => $IGIni->variable( 'instagram', 'RedirectURI' )
22
);
23
$tokenArray = eZIG::fetchAll( );
24
if( count( $tokenArray ) > 0 )
25
{
26
        foreach( $tokenArray as $item )
27
        {
28
                $userArray[ $item->attribute('ig_id') ] = $item->attribute('accessToken');
29
        }
30
 
31
}
32
else
33
        return;
34
 
35
$defaultTagsArray = $IGIni->variable( 'DefaultTagsSettings', 'DefaultTags' );
36
$setLikesArray = array( 10, 15, 20, 25, 30, 40, 50, 100 );
37 4 ffruehstueck
 
38 2 ffruehstueck
//Looping through all the collected images.
39
foreach( $allImageArray as $image )
40
{
41
 
42
        $instagram = new Instagram($config);
43
        $instagram->setAccessToken( $userArray[ $image->attribute('user_id')] );
44
 
45
        $tagCount = count( explode( " #", $image->attribute('tags') ) );
46
 
47
        $newTags = array();
48
        shuffle( $defaultTagsArray );
49
        foreach( $defaultTagsArray as $tag )
50
        {
51
                if( !strstr( $image->attribute('tags'), $tag) )
52
                        $newTags[] = ' #'.$tag;
53
                if( ( count( $newTags ) + $tagCount ) > 29 )
54
                        break;
55
        }
56
 
57
        for( $i=$image->attribute('likes');  $i > 0; $i=$i-5 )
58
        {
59
                if( in_array( $i, $setLikesArray ) )
60
                {
61
                        $tag = $i."likes";
62 4 ffruehstueck
 
63 2 ffruehstueck
                        if( !strstr( $image->attribute('tags'), $tag) )
64
                                $newTags[] = ' #'.$tag;
65
                        if( ( count( $newTags ) + $tagCount ) > 29 )
66
                                break;
67
                }
68
 
69
        }
70 4 ffruehstueck
        /*
71
         * if there are new tags for the image it will be posted to instagram
72
         */
73 2 ffruehstueck
        if( count( $newTags ) )
74
                $ret = $instagram->postMediaComment( $image->attribute('id'), implode("",$newTags) );
75
 
76
}
77
 
78
$cli->notice("Instagram set default tags FINISHED");
79
 
80
?>