/web/htdocs/www.euroroma.net/home/zenphoto/zp-core/zp-extensions/seo_cleanup.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
 * SEO file/folder name clenser
 *
 * This plugin will scan your images and albums for file/folder names that are not <i>SEO friendly</i>.
 * It will rename those that found needing improvement replacing offending characters with friendly equivalents.
 *
 * Note: Clicking the button causes this process to execute. There is no <i>undo</i>.
 *
 * @author Stephen Billard (sbillard)
 * @package plugins
 * @subpackage seo
 */
if (defined('OFFSET_PATH')) {
    
$plugin_is_filter ADMIN_PLUGIN;
    
$plugin_description gettext("Provides a utility SEO file/folder name clenser.");
    
$plugin_author "Stephen Billard (sbillard)";

    
zp_register_filter('admin_utilities_buttons''seo_cleanup_button');

    function 
seo_cleanup_button($buttons) {
        
$buttons[] = array(
                        
'XSRFTag'             => 'seo_cleanup',
                        
'category'         => gettext('Seo'),
                        
'enable'             => true,
                        
'button_text'     => gettext('SEO Cleaner'),
                        
'formname'         => 'seo_cleanup.php',
                        
'action'             => WEBPATH '/' ZENFOLDER '/' PLUGIN_FOLDER '/seo_cleanup.php',
                        
'icon'                 => 'images/redo.png',
                        
'title'                 => gettext('Make file and folder names in the Gallery SEO friendly.'),
                        
'alt'                     => '',
                        
'hidden'             => '',
                        
'rights'             => ADMIN_RIGHTS
        
);
        return 
$buttons;
    }

} else {

    
define('OFFSET_PATH'3);
    require_once(
dirname(dirname(__FILE__)) . '/admin-globals.php');

    
admin_securityChecks(ALBUM_RIGHTScurrentRelativeURL());

    
XSRFdefender('seo_cleanup');

    function 
getE($e) {
        switch (
$e) {
            case 
2:
                return 
gettext("Image already exists.");
            case 
3:
                return 
gettext("Album already exists.");
            case 
4:
                return 
gettext("Cannot move, copy, or rename to a subalbum of this album.");
            case 
5:
                return 
gettext("Cannot move, copy, or rename to a dynamic album.");
            case 
6:
                return 
gettext('Cannot rename an image to a different suffix');
            case 
7:
                return 
gettext('Album delete failed');
            default:
                return 
sprintf(gettext("There was an error #%d with the rename operation."), $e);
        }
    }

    function 
cleanAlbum($obj) {
        global 
$albumcount;
        
$display true;
        
$subalbum $obj->name;
        
$file basename($subalbum);
        
$seoname seoFriendly($file);
        if (
$seoname != $file) {
            if (
$display) {
                
$name dirname($subalbum);
                if (
$name == '.') {
                    
$name '';
                }
                echo 
'<p class="notebox">' $name "</p>\n";
                
$display false;
            }
            
$newname dirname($subalbum);
            if (empty(
$newname) || $newname == '.') {
                
$newname $seoname;
            } else {
                
$newname .= '/' $seoname;
            }
            if (
$e $obj->rename($newname)) {
                
$error getE($e$subalbum$newname);
                
printf(gettext('<em>%1$s</em> rename to <em>%2$s</em> failed: %3$s'), $subalbum$newname$error);
                echo 
"<br />\n";
            } else {
                
printf(gettext('<em>%1$s</em> renamed to <em>%2$s</em>'), $subalbum$newname);
                echo 
"<br />\n";
                
$albumcount++;
            }
        }
        if (!
$obj->isDynamic())
            
checkFolder($obj);
    }

    function 
checkFolder($album) {
        
$display true;

        global 
$albums$count$albumcount;
        
$albums $album->getAlbums(0);
        foreach (
$albums as $subalbum) {
            
$obj newAlbum($subalbum);
            
cleanAlbum($obj);
        }
        
$display true;
        
$files $album->getImages(0);
        foreach (
$files as $filename) {
            
$seoname seoFriendly($filename);
            if (
stripSuffix($seoname) != stripSuffix($filename)) {
                if (
$display) {
                    echo 
'<p class="notebox">' $album->name "</p>\n";
                    
$display false;
                }
                
$image newImage($album$filename);
                if (
$e $image->rename($seoname)) {
                    
$error getE($e$filename$seoname);
                    
printf(gettext('<em>%1$s</em> rename to <em>%2$s</em> failed: %3$s'), $filename$seoname$error);
                    echo 
"<br />\n";
                } else {
                    echo 
'&nbsp;&nbsp;';
                    
printf(gettext('<em>%1$s</em> renamed to <em>%2$s</em>'), $filename$seoname);
                    echo 
"<br />\n";
                    
$count++;
                }
            }
        }
    }

    
$zenphoto_tabs['overview']['subtabs'] = array(gettext('SEO cleaner') => '');
    
printAdminHeader('overview''SEO cleaner');

    if (isset(
$_GET['todo'])) {
        
$count sanitize_numeric($_GET['imagecount']);
        
$albumcount sanitize_numeric($_GET['albumcount']);
        
$albums = array();
        foreach (
explode(','sanitize(sanitize($_GET['todo']))) as $album) {
            
$albums[] = sanitize($album);
        }
    } else {
        
$count 0;
        
$albumcount 0;
        
$albums $_zp_gallery->getAlbums();
    }
    
?>
    <?php echo '</head>'?>
    <body>
        <?php printLogoAndLinks(); ?>
        <div id="main">
            <?php printTabs(); ?>
            <div id="content">
                <?php printSubtabs(); ?>
                <div class="tabbox">
                    <?php zp_apply_filter('admin_note''seo_cleanup'''); ?>
                    <h1><?php echo gettext('Cleanup album and image names to be SEO friendly'); ?></h1>
                    <?php
                    
foreach ($albums as $album) {
                        
$obj newAlbum($album);
                        
cleanAlbum($obj);
                        
?>
                        <?php
                    
}
                    
?>
                </div>
            </div><!-- content -->
        </div><!-- main -->
        <?php printAdminFooter(); ?>
    </body>
    <?php
    
echo "</html>";
}
?>